home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-21 | 115.1 KB | 3,921 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // File: U3DDrawing.cp
- //
- // Contains: Adorners, classes, etc for 3D drawing effects
- //
- // Written by: Jamie Osborne, Robin Mair, Faulkner White, Henri Lamiraux
- // Adapted for 3.1.1 by Jeroen Schalk
- //
- // Copyright: © 1992-1994 by Apple Computer, Inc.
- //
- // Some notes:
- // 1. This code makes your controls non-internationalized. If you wish
- // to make the controls draw with the correct system orientation
- // (e.g. right to left for Hebrew), you need to check the gEnvironment
- // variable and setup your drawing rects correctly.
- // 2. This code IS compatible with non-Color Quickdraw machines.
- // 3. On slower machines (anything slower than an '030), this code will
- // be slow. You should take this into account if you use this library
- // in your application. Test it out on a slower machine to see if
- // it is still fast enough for your needs. If it IS too slow, there
- // are many opportunities in the code for optimization. One example
- // is removing some of the CGraphicsState objects from some of the
- // routines and replacing them with CPenNormal();
- // 4. If you have any questions about the code, please direct them to
- // Jamie Osborne (AppleLink: JWO; Internet: jwo@applelink.apple.com).
- //----------------------------------------------------------------------------------------
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __U3DDRAWING__
- #include "U3DDrawing.h"
- #endif
-
- //----------------------------------------------------------------------------------------
- // InitU3DDrawing Include this routine in your initialization function
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
-
- void InitU3DDrawing()
- {
- macroDontDeadStrip(TGrayBackgroundAdorner);
- macroDontDeadStrip(TWhiteBackgroundAdorner);
- macroDontDeadStrip(T3DGrayBackgroundAdorner);
- macroDontDeadStrip(T3DFrameAdorner);
- macroDontDeadStrip(T3DLineTopAdorner);
- macroDontDeadStrip(T3DLineBottomAdorner);
- macroDontDeadStrip(T3DLineRightAdorner);
- macroDontDeadStrip(T3DLineLeftAdorner);
-
- macroDontDeadStrip(T3DCheckBox);
- macroDontDeadStrip(T3DRadio);
- macroDontDeadStrip(T3DButton);
-
- macroDontDeadStrip(T3DIconAdorner);
- macroDontDeadStrip(TIconSuite);
- macroDontDeadStrip(T3DIconButton);
- }
-
- //----------------------------------------------------------------------------------------
- // ••• 3D Utility Classes •••
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // CLASS: CGraphicsState
- //----------------------------------------------------------------------------------------
- //
- // This class is used to save and restore the current Quickdraw graphics state.
- // Create one of these objects at the beginning of a drawing method then use it to
- // save and restore the state of the graphics before and after your drawing. When
- // one of these objects is created the Constructor saves off the current settings
- // for the fore and background colors, the pen state and the current textstyle. It
- // also does a PenNormal() call in preparation for drawing. The destructor will just
- // reverse this process. Two methods are provided that allow an explicit Save() and
- // Restore() that mimic the constructor and destructor. These method can be called
- // if you want to reuse the same object during drawing. The destructor will use the
- // last values saved.
-
- //----------------------------------------------------------------------------------------
- // CGraphicsState::CGraphicsState
- //----------------------------------------------------------------------------------------
- //
- // Initialize the instance variables of the object by saving the current state
- // of some of the current port settings.
-
- #pragma segment AUtils
-
- CGraphicsState::CGraphicsState ()
- {
- // • First save off the foreground and background colors and the penstate
- GetIfColor ( fSaveForeColor );
- GetIfBkColor ( fSaveBackColor );
- GetPenState ( &fSavePenState );
- CPenNormal ();
-
- // • Now save off the current port's textstyle information
- GetPortTextStyle ( fSaveTextStyle );
-
- } // CGraphicsState::CGraphicsState
-
- //----------------------------------------------------------------------------------------
- // CGraphicsState::~CGraphicsState
- //----------------------------------------------------------------------------------------
- //
- // The destructor simply restores the last Save() state when it is called
-
- #pragma segment AUtils
-
- CGraphicsState::~CGraphicsState ()
- {
- // • Restore the foreground and background colors and the penstate
- SetIfColor ( fSaveForeColor );
- SetIfBkColor ( fSaveBackColor );
- SetPenState ( &fSavePenState );
-
- // • Now restore the textstyle of the current port
- SetPortTextStyle ( fSaveTextStyle );
-
- } // CGraphicsState::~CGraphicsState
-
- //----------------------------------------------------------------------------------------
- // CGraphicsState::Save
- //----------------------------------------------------------------------------------------
- //
- // Save off the current graphics state so that we can restore it again
- // after we are done with our drawing. Also calls PenNormal () to set the
- // pen to the Quickdraw defaults.
-
- #pragma segment AUtils
-
- void CGraphicsState::Save ()
- {
- // • First save off the foreground and background colors and the penstate
- GetIfColor ( fSaveForeColor );
- GetIfBkColor ( fSaveBackColor );
- GetPenState ( &fSavePenState );
- CPenNormal ();
-
- // • Now save off the current port's textstyle information
- GetPortTextStyle ( fSaveTextStyle );
-
- } // CGraphicsState::Save
-
- //----------------------------------------------------------------------------------------
- // CGraphicsState::Restore
- //----------------------------------------------------------------------------------------
- //
- // Restores the graphics state, this is typically called after doing some drawing
- // and after we have created an instance of this class or called the Save () method.
-
- #pragma segment AUtils
-
- void CGraphicsState::Restore ()
- {
- // • Restore the foreground and background colors and the penstate
- SetIfColor ( fSaveForeColor );
- SetIfBkColor ( fSaveBackColor );
- SetPenState ( &fSavePenState );
-
- // • Now restore the textstyle of the current port
- SetPortTextStyle ( fSaveTextStyle );
-
- } // CGraphicsState::Restore
-
- //----------------------------------------------------------------------------------------
- // Class CDrawPerDevice
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // CDrawPerDevice::CDrawPerDevice
- //----------------------------------------------------------------------------------------
- #pragma segment AUtils
-
- CDrawPerDevice::CDrawPerDevice()
- {
- // • Initialize our instance variables
- fSaveClip = NULL;
- fGDHandle = NULL;
-
- } // CDrawPerDevice::CDrawPerDevice
-
- //----------------------------------------------------------------------------------------
- // CDrawPerDevice::CDrawPerDevice
- //----------------------------------------------------------------------------------------
- #pragma segment AUtils
-
- CDrawPerDevice::CDrawPerDevice ( const CRect& area )
- {
- // • Initialize our fields
- fSaveClip = NULL;
- fGDHandle = NULL;
-
- // • Save off the area passed in and convert it to global coordinates
- fGlobalArea = area;
- LocalToGlobal ( fGlobalArea[topLeft] );
- LocalToGlobal ( fGlobalArea[botRight] );
-
- // Remember the View port info
- fFocus.itsViewPortInfo.clip = MakeNewRgn();
- GetFocus(fFocus);
-
- fSaveClip = fFocus.itsViewPortInfo.clip;
-
- // Set a placeholder for non Color QD drawing
- fDoneOldQD = false;
- } // CDrawPerDevice::CDrawPerDevice
-
- //----------------------------------------------------------------------------------------
- // CDrawPerDevice::~CDrawPerDevice
- //----------------------------------------------------------------------------------------
- #pragma segment AUtils
-
- CDrawPerDevice::~CDrawPerDevice()
- {
- // Restore the port information
- SetFocus(fFocus);
-
- // • If we have a saved clip then make sure that we displose of the region
- fFocus.itsViewPortInfo.clip = DisposeIfRgnHandle(fFocus.itsViewPortInfo.clip);
-
- } // CDrawPerDevice::~CDrawPerDevice
-
- //----------------------------------------------------------------------------------------
- // CDrawPerDevice::SetDrawingArea
- //----------------------------------------------------------------------------------------
- //
- // This does the same thing as the constructor and can be used to reset the drawing
- // area at anytime
-
- #pragma segment AUtils
-
- void CDrawPerDevice::SetDrawingArea ( const CRect& area )
- {
- // • Save off the area passed in and convert it to global coordinates
- fGlobalArea = area;
- LocalToGlobal ( fGlobalArea[topLeft] );
- LocalToGlobal ( fGlobalArea[botRight] );
-
- // • Get a handle to the first device in the device list
- fGDHandle = GetDeviceList ();
-
- // Remember the View port info
- fFocus.itsViewPortInfo.clip = MakeNewRgn();
- GetFocus(fFocus);
-
- fSaveClip = fFocus.itsViewPortInfo.clip;
-
- } // CDrawPerDevice::SetDrawingArea
-
- //----------------------------------------------------------------------------------------
- // CDrawPerDevice::NextDevice
- //----------------------------------------------------------------------------------------
- //
- // This is the method that is called during the drawing process. What it does is
- // cycle through each of the devices in the device list, returning the pixel size for
- // the device, it also sets the clipping to the portion of the drawing area that is
- // in need of drawing on the current device
-
- #pragma segment AUtils
-
- Boolean CDrawPerDevice::NextDevice ( short& pixelSize )
- {
- Boolean foundActiveScreen = false;
- CRect bounds;
- CRect area;
-
- // Go ye not into this code if ye have not Color Quickdraw
- if (!gConfiguration.hasColorQD)
- {
- pixelSize = 1;
- foundActiveScreen = !fDoneOldQD;
- fDoneOldQD = !fDoneOldQD;
- return foundActiveScreen;
- }
-
- // • We will iterate over the device list while there are devices. As we do this
- // are returning the pixel size of the current device and setting the clipping to
- // the area of that device that is in need of redrawing
-
- if (fGDHandle == NULL)
- fGDHandle = GetDeviceList();
- else
- fGDHandle = GetNextDevice(fGDHandle);
-
- while ((fGDHandle != NULL) && (foundActiveScreen == false))
- {
- if (TestDeviceAttribute(fGDHandle, screenDevice) &&
- TestDeviceAttribute(fGDHandle, screenActive))
- {
- foundActiveScreen = true;
- pixelSize = (*(*fGDHandle)->gdPMap)->pixelSize;
-
- // • Get the bounds of the current device
- bounds = (*fGDHandle)->gdRect;
- if ( SectRect ( bounds, fGlobalArea, area ) )
- {
- // • Convert the overlapping area to local coordinates
- GlobalToLocal ( area[topLeft] );
- GlobalToLocal ( area[botRight] );
-
- // • Create a temporary region and convert the overlapped area to a region
- CTemporaryRegion tempRgn;
- RectRgn ( tempRgn, area );
-
- // • Set the temporary region to the intersection between the area and the
- // saved clipping region
- SectRgn ( tempRgn, fSaveClip, tempRgn );
- // Clip to the visregion,too
- SectRgn(tempRgn, qd.thePort->visRgn, tempRgn);
-
- // • Set the clip to the overlap
- SetClip ( tempRgn );
-
- }
- else
- {
- foundActiveScreen = false;
- fGDHandle = GetNextDevice(fGDHandle);
- }
- }
- else
- fGDHandle = GetNextDevice(fGDHandle);
- }
-
- return foundActiveScreen;
-
- } // CDrawPerDevice::NextDevice
-
- //----------------------------------------------------------------------------------------
- // CPenNormal - a color version of PenNormal()
- //----------------------------------------------------------------------------------------
- #pragma segment AUtils
-
- void CPenNormal()
- {
- RGBForeColor(gRGBBlack);
- RGBBackColor(gRGBWhite);
- PenNormal();
-
- } // CPenNormal
-
- //----------------------------------------------------------------------------------------
- // ••• 3D TView Adorners •••
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- #undef Inherited
- #define Inherited TAdorner
- DefineClass(TWhiteBackgroundAdorner, Inherited);
-
- TWhiteBackgroundAdorner::TWhiteBackgroundAdorner()
- {
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- void TWhiteBackgroundAdorner::IWhiteBackgroundAdorner(Boolean freeOnDeletion)
- {
- this->IAdorner(kWhiteBackgroundAdorner,freeOnDeletion);
-
- } // T3DWhiteBackgroundAdorner::I3DWhiteBackgroundAdorner
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DRes
-
- void TWhiteBackgroundAdorner::Draw(TView* itsView, const VRect& area)
- {
- CRect qdArea;
- short pixelSize;
- CGraphicsState rememberGState;
-
- itsView->ViewToQDRect(area, qdArea);
-
- CDrawPerDevice device(qdArea);
- while (device.NextDevice(pixelSize))
- {
- // Only draw us if we are on a non B & W monitor
- if (pixelSize >= 4)
- {
- SetIfBkColor(gRGBWhite);
- EraseRect(qdArea);
- }
- }
- } // TWhiteBackgroundAdorner::Draw
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- #undef Inherited
- #define Inherited TAdorner
- DefineClass(TGrayBackgroundAdorner, Inherited);
-
- TGrayBackgroundAdorner::TGrayBackgroundAdorner()
- {
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- void TGrayBackgroundAdorner::IGrayBackgroundAdorner(Boolean freeOnDeletion)
- {
- this->IAdorner(kGrayBackgroundAdorner,freeOnDeletion);
-
- } // T3DGrayBackgroundAdorner::I3DGrayBackgroundAdorner
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DRes
-
- void TGrayBackgroundAdorner::Draw(TView* itsView, const VRect& area)
- {
-
- CRect qdArea;
- short pixelSize;
- CGraphicsState rememberGState;
-
- itsView->ViewToQDRect(area, qdArea);
-
- CDrawPerDevice device(qdArea);
- while (device.NextDevice(pixelSize))
- {
- if (pixelSize >= 4)
- {
- // Erase because we want our subviews to draw on gray
- SetIfBkColor(kLightGray);
- EraseRect(qdArea);
- }
- }
- } // TGrayBackgroundAdorner::Draw
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- #undef Inherited
- #define Inherited TGrayBackgroundAdorner
- DefineClass(T3DGrayBackgroundAdorner, Inherited);
-
- T3DGrayBackgroundAdorner::T3DGrayBackgroundAdorner()
- {
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- void T3DGrayBackgroundAdorner::I3DGrayBackgroundAdorner(Boolean freeOnDeletion)
- {
- this->IGrayBackgroundAdorner(freeOnDeletion);
-
- } // T3DGrayBackgroundAdorner::I3DGrayBackgroundAdorner
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DRes
-
- void T3DGrayBackgroundAdorner::Draw(TView* itsView, const VRect& area)
- {
- CRect qdArea, frame;
- VRect viewRect;
- short pixelSize;
- CGraphicsState rememberGState;
-
- // Erase the background in gray
- Inherited:: Draw(itsView,area);
-
- itsView->ViewToQDRect(area, qdArea);
- itsView->GetAdornExtent(viewRect);
- itsView->ViewToQDRect(viewRect, frame);
-
- CDrawPerDevice device(qdArea);
- while (device.NextDevice(pixelSize))
- {
- // Only draw on non- B & W
- if (pixelSize >= 4)
- {
- SetIfColor(gRGBWhite);
- MoveTo(frame.right-1, frame.top);
- LineTo(frame.left, frame.top);
- LineTo(frame.left, frame.bottom);
-
- SetIfColor(kMediumLightGray);
- MoveTo(frame.left+1, frame.bottom-1);
- LineTo(frame.right-1, frame.bottom-1);
- LineTo(frame.right-1, frame.top+1);
- }
- }
-
- } // T3DGrayBackgroundAdorner::Draw
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- #undef Inherited
- #define Inherited TAdorner
- DefineClass(T3DLineTopAdorner, Inherited);
-
- T3DLineTopAdorner::T3DLineTopAdorner()
- {
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- void T3DLineTopAdorner::I3DLineTopAdorner(Boolean freeOnDeletion)
- {
- this->IAdorner(k3DLineTopAdorner,freeOnDeletion);
-
- } // T3DLineTopAdorner::I3DLineTopAdorner
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DRes
-
- void T3DLineTopAdorner::Draw(TView* itsView, const VRect& area)
- {
- CRect qdArea, frame;
- VRect viewRect;
- short pixelSize;
- CGraphicsState rememberGState;
-
- itsView->ViewToQDRect(area, qdArea);
- itsView->GetAdornExtent(viewRect);
- itsView->ViewToQDRect(viewRect, frame);
-
- CDrawPerDevice device(qdArea);
- while (device.NextDevice(pixelSize))
- {
- // Draw a gray and white line for non- B & W
- if (pixelSize >= 4)
- {
- SetIfColor(kMediumLightGray);
- MoveTo(frame.left, frame.top);
- LineTo(frame.right, frame.top);
-
- SetIfColor(gRGBWhite);
- MoveTo(frame.left, frame.top + 1);
- LineTo(frame.right, frame.top + 1);
- }
- // Draw a regular black line
- else
- {
-
- PenPat(&qd.black);
- MoveTo(frame.left, frame.top);
- LineTo(frame.right, frame.top);
- }
- }
-
- } // T3DLineTopAdorner::Draw
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- #undef Inherited
- #define Inherited TAdorner
- DefineClass(T3DLineBottomAdorner, Inherited);
-
- T3DLineBottomAdorner::T3DLineBottomAdorner()
- {
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- void T3DLineBottomAdorner::I3DLineBottomAdorner(Boolean freeOnDeletion)
- {
- this->IAdorner(k3DLineBottomAdorner,freeOnDeletion);
-
- } // T3DLineBottomAdorner::I3DLineBottomAdorner
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DRes
-
- void T3DLineBottomAdorner::Draw(TView* itsView, const VRect& area)
- {
- CRect qdArea, frame;
- VRect viewRect;
- short pixelSize;
- CGraphicsState rememberGState;
-
- itsView->ViewToQDRect(area, qdArea);
- itsView->GetAdornExtent(viewRect);
- itsView->ViewToQDRect(viewRect, frame);
-
- CDrawPerDevice device(qdArea);
- while (device.NextDevice(pixelSize))
- {
- // Draw a gray and white line for non- B & W
- if (pixelSize >= 4)
- {
- SetIfColor(kMediumLightGray);
- MoveTo(frame.left, frame.bottom - 1);
- LineTo(frame.right, frame.bottom - 1);
-
- SetIfColor(gRGBWhite);
- MoveTo(frame.left, frame.bottom);
- LineTo(frame.right, frame.bottom);
- }
- // Draw a regular black line
- else
- {
-
- PenPat(&qd.black);
- MoveTo(frame.left, frame.bottom - 1);
- LineTo(frame.right, frame.bottom - 1);
- }
- }
-
- } // T3DLineBottomAdorner::Draw
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- #undef Inherited
- #define Inherited TAdorner
- DefineClass(T3DLineLeftAdorner, Inherited);
-
- T3DLineLeftAdorner::T3DLineLeftAdorner()
- {
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- void T3DLineLeftAdorner::I3DLineLeftAdorner(Boolean freeOnDeletion)
- {
- this->IAdorner(k3DLineLeftAdorner,freeOnDeletion);
-
- } // T3DLineLeftAdorner::I3DLineLeftAdorner
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DRes
-
- void T3DLineLeftAdorner::Draw(TView* itsView, const VRect& area)
- {
- CRect qdArea, frame;
- VRect viewRect;
- short pixelSize;
- CGraphicsState rememberGState;
-
- itsView->ViewToQDRect(area, qdArea);
- itsView->GetAdornExtent(viewRect);
- itsView->ViewToQDRect(viewRect, frame);
-
- CDrawPerDevice device(qdArea);
- while (device.NextDevice(pixelSize))
- {
- // Draw a gray and white line for non- B & W
- if (pixelSize >= 4)
- {
- SetIfColor(kMediumLightGray);
- MoveTo(frame.left, frame.top);
- LineTo(frame.left, frame.bottom);
-
- SetIfColor(gRGBWhite);
- MoveTo(frame.left + 1, frame.top);
- LineTo(frame.left + 1, frame.bottom);
- }
- // Draw a regular black line
- else
- {
-
- PenPat(&qd.black);
- MoveTo(frame.left, frame.top);
- LineTo(frame.left, frame.bottom);
- }
- }
-
- } // T3DLineLeftAdorner::Draw
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- #undef Inherited
- #define Inherited TAdorner
- DefineClass(T3DLineRightAdorner, Inherited);
-
- T3DLineRightAdorner::T3DLineRightAdorner()
- {
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- void T3DLineRightAdorner::I3DLineRightAdorner(Boolean freeOnDeletion)
- {
- this->IAdorner(k3DLineRightAdorner,freeOnDeletion);
-
- } // T3DLineRightAdorner::I3DLineRightAdorner
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DRes
-
- void T3DLineRightAdorner::Draw(TView* itsView, const VRect& area)
- {
- CRect qdArea, frame;
- VRect viewRect;
- short pixelSize;
- CGraphicsState rememberGState;
-
- itsView->ViewToQDRect(area, qdArea);
- itsView->GetAdornExtent(viewRect);
- itsView->ViewToQDRect(viewRect, frame);
-
- CDrawPerDevice device(qdArea);
- while (device.NextDevice(pixelSize))
- {
- // Draw a gray and white line for non- B & W
- if (pixelSize >= 4)
- {
- SetIfColor(kMediumLightGray);
- MoveTo(frame.right - 1, frame.top);
- LineTo(frame.right -1, frame.bottom);
-
- SetIfColor(gRGBWhite);
- MoveTo(frame.right, frame.top);
- LineTo(frame.right, frame.bottom);
- }
- // Draw a regular black line
- else
- {
- PenPat(&qd.black);
- MoveTo(frame.right - 1, frame.top);
- LineTo(frame.right - 1, frame.bottom);
- }
- }
-
- } // T3DLineRightAdorner::Draw
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- #undef Inherited
- #define Inherited TAdorner
- DefineClass(T3DFrameAdorner, Inherited);
-
- T3DFrameAdorner::T3DFrameAdorner()
- {
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DOpen
-
- void T3DFrameAdorner::I3DFrameAdorner(Boolean freeOnDeletion)
- {
- this->IAdorner(k3DFrameAdorner,freeOnDeletion);
-
- } // T3DFrameAdorner::I3DFrameAdorner
-
- //----------------------------------------------------------------------------------------
- #pragma segment A3DRes
-
- void T3DFrameAdorner::Draw(TView* itsView, const VRect& area)
- {
- CRect qdArea, frame;
- VRect viewRect;
- short pixelSize;
- CGraphicsState rememberGState;
-
- itsView->ViewToQDRect(area, qdArea);
- itsView->GetAdornExtent(viewRect);
- itsView->ViewToQDRect(viewRect, frame);
-
- CDrawPerDevice device(qdArea);
- while (device.NextDevice(pixelSize))
- {
- // Draw a gray and white frame with black outline
- if (pixelSize >= 4) {
-
- SetIfColor(kMediumLightGray);
- MoveTo(frame.right, frame.top);
- LineTo(frame.left, frame.top);
- LineTo(frame.left, frame.bottom);
-
- SetIfColor(gRGBWhite);
- MoveTo(frame.left +1, frame.bottom -1);
- LineTo(frame.right -1, frame.bottom -1);
- LineTo(frame.right -1, frame.top + 1);
-
- SetIfColor(gRGBBlack);
- InsetRect(frame, 1, 1);
- FrameRect(frame);
- InsetRect(frame, -1, -1);
- }
- // Draw a regular frame
- else
- {
- PenPat(&qd.black);
- InsetRect(frame, 1, 1);
- FrameRect(frame);
- InsetRect(frame, -1, -1);
- }
- }
-
- } // T3DFrameAdorner::Draw
-
- //----------------------------------------------------------------------------------------
- // ••• TControl classes and auxiliary adorners •••
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::Initialize
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- #undef Inherited
- #define Inherited TCheckBox
- DefineClass(T3DCheckBox, Inherited);
-
- void T3DCheckBox::Initialize () // OVERRIDE
- {
- fBackColor = kLightGray;
- fForeColor = gRGBBlack;
- fDrawBox = VRect(1, 0, 15, 14); // A standard check box is 14x14
-
- } // T3DCheckBox::Initialize
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::DoPostCreate
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void T3DCheckBox::DoPostCreate (TDocument *itsDocument) // OVERRIDE
- {
- VRect theRect;
- TDrawingEnvironment *environment;
-
- Inherited::DoPostCreate (itsDocument);
-
- // If we have a drawing environment, use it for drawing!
- if (environment = this->GetDrawingEnvironment())
- {
- this->SetBackColor(environment->fBackgroundColor);
- this->InstallColor(environment->fForegroundColor, false);
- }
- this->ControlArea(theRect);
-
- // Center the check box vertically
- long height = theRect.bottom - theRect.top;
- height -= 14;
- long top = height / 2;
- fDrawBox.top += top;
- fDrawBox.bottom += top;
-
- } // T3DCheckBox::DoPostCreate
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::I3DCheckBox
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void T3DCheckBox::I3DCheckBox (TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, const CStr255& itsLabel,
- Boolean isTurnedOn)
- {
- VRect theRect;
- TDrawingEnvironment *environment;
-
- this->ICheckBox (itsSuperView, itsLocation, itsSize,
- itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn);
-
- // If we have a drawing environment, use it for drawing!
- if (environment = this->GetDrawingEnvironment())
- {
- this->SetBackColor(environment->fBackgroundColor);
- this->InstallColor(environment->fForegroundColor, false);
- }
- this->ControlArea(theRect);
-
- // Center the check box vertically
- long height = theRect.bottom - theRect.top;
- height -= 14;
- long top = height / 2;
- fDrawBox.top += top;
- fDrawBox.bottom += top;
-
- } // T3DCheckBox::I3DCheckBox
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::Clone
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- TObject* T3DCheckBox::Clone () // OVERRIDE
- {
- T3DCheckBox* aClonedCheckBox = (T3DCheckBox *)(Inherited::Clone ());
-
- aClonedCheckBox->fBackColor = fBackColor;
- aClonedCheckBox->fForeColor = fForeColor;
-
- return aClonedCheckBox;
-
- } // T3DCheckBox::Clone
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::Free
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlClose
-
- void T3DCheckBox::Free () // OVERRIDE
- {
- Inherited::Free ();
-
- } // T3DCheckBox::Free
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DCheckBox::Draw (const VRect& /*area*/)
- {
- VRect theRect;
- CRect qdArea;
- CStr255 label;
- CGraphicsState remember;
-
- this->ControlArea(theRect);
- this->ViewToQDRect(theRect, qdArea);
-
- this->DrawBox();
- this->DrawCheck();
-
- this->GetText (label);
- CRect textBox = qdArea;
-
- // Move the text 3 pixels to the right of the check box
- textBox.left += (short) fDrawBox.right + 3;
- this->DrawBoxText (label, textBox, false);
-
- } // T3DCheckBox::Draw
-
- //----------------------------------------------------------------------------------------
- // T3DButton::DoMouseCommand
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlSelCommand
-
- void T3DCheckBox::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* ,
- CPoint) // override
- {
- TControlTracker * aControlTracker = new TControlTracker;
- aControlTracker->IControlTracker(this, theMouse);
- this->PostCommand(aControlTracker);
- } // T3DCheckBox::DoMouseCommand
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::TrackMouse
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlSelCommand
-
- void T3DCheckBox::TrackMouse(TrackPhase aTrackPhase,
- VPoint& ,
- // anchorPoint
- VPoint& ,
- // previousPoint
- VPoint& nextPoint,
- Boolean) // OVERRIDE
- {
- Boolean state = false;
-
- if (! this->IsDimmed())
- {
- switch (aTrackPhase)
- {
- case trackBegin:
- state = fHilite;
- this->HiliteState(true, kRedraw);
- break;
- case trackContinue:
- if (this->ContainsMouse(nextPoint))
- this->HiliteState(true, kRedraw);
- else
- this->HiliteState(state, kRedraw);
- break;
- case trackEnd:
- if (this->ContainsMouse(nextPoint))
- {
- this->HiliteState(false, this->IsOn());
- this->HandleEvent(fEventNumber, this, NULL);
- }
- break;
- }
- }
- } // T3DCheckBox::TrackMouse
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::SetLongVal:
- // Override the way the control works so that we don't call the CDEF
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DCheckBox::SetLongVal(VCoordinate itsVal, Boolean /*redraw*/)
- {
- itsVal = Max(fLongMin, Min(itsVal, fLongMax));
- if (itsVal != fLongVal)
- {
- fLongVal = itsVal;
- CRect tempRect;
- this->ViewToQDRect(fDrawBox, tempRect);
- InsetRect(tempRect, 2,2);
- this->InvalidateRect(tempRect);
- }
- } // T3DCheckBox::SetLongVal
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::HiliteState:
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void T3DCheckBox::HiliteState(Boolean state,Boolean redraw)
- {
- if (state != fHilite)
- {
- fHilite = state;
- if (state) // hilite adorner draws the hilite state
- this->AddAdorner(gHiliteAdorner, kAdornLast - 5, kDontRedraw);
- else
- this->DeleteAdorner(gHiliteAdorner, kDontRedraw);
- if (redraw)
- this->Hilite();
- }
- } // T3DCheckBox::HiliteState
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::DimState:
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void T3DCheckBox::DimState(Boolean state, Boolean redraw)
- {
- if (state != fDimmed)
- {
- fDimmed = state;
- if (state) // dim adorner draws the dim state
- this->AddAdorner(gDimAdorner, kAdornLast - 10, kDontRedraw);
- else
- this->DeleteAdorner(gDimAdorner, kDontRedraw);
- if (redraw)
- this->DrawContents(); // Draw change immediately
- }
- } // T3DCheckBox::DimState
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::Hilite
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DCheckBox::Hilite () // OVERRIDE
- {
- VRect area;
- CRect qdArea, qdBox;
- CGraphicsState rememberGState;
-
- #if qDebug
- this->AssumeFocused ();
- #endif
-
- this->ControlArea (area);
- this->ViewToQDRect (area, qdArea);
- this->ViewToQDRect(fDrawBox, qdBox);
-
- CPenNormal();
- if (fHilite)
- {
- InsetRect(qdBox, 2, 2);
- FrameRect(qdBox);
- }
- else
- this->DrawCheck();
- } // T3DCheckBox::Hilite
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::Dim
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DCheckBox::Dim () // OVERRIDE
- {
- VRect area;
- CRect qdArea;
- CGraphicsState rememberGState;
-
- this->ControlArea (area);
- area.left += fDrawBox.right;
- this->ViewToQDRect (area, qdArea);
-
- short pixelSize;
- CDrawPerDevice device(qdArea);
- while (device.NextDevice (pixelSize))
- {
- // If in B & W, do the standard gray pattern. Non B & W is taken care of in
- // the DrawCheck and DrawBox routines
- if (pixelSize < 2)
- {
- #if qDebug
- this->AssumeFocused ();
- #endif
-
- InsetRect (qdArea, 1, 1);
-
- PenPat (&qd.gray);
- PenMode (patBic);
- PaintRect (qdArea);
-
- InsetRect (qdArea, -1, -1);
- }
- }
- } // T3DCheckBox::Dim
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::DrawBoxText
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DCheckBox::DrawBoxText (const CStr255& s, const CRect& box, Boolean preferOutline)
- {
- FontInfo theFontInfo;
- CRect localBox = box;
- CRect qdArea;
- CGraphicsState rememberGState;
-
- CWhileOutlinePreferred setOP (preferOutline);
-
- short textHeight = MAGetFontInfo (theFontInfo);
- CPoint boxSize = localBox.GetSize ();
-
- // Center the text vertically
- localBox.top += (boxSize.v - textHeight) / 2;
- MoveTo (localBox.left, localBox.top + theFontInfo.ascent);
-
- short pixelSize;
- CDrawPerDevice device(localBox);
- while (device.NextDevice (pixelSize))
- {
- // If we're dimmed, draw in gray, else draw in the fore color
- if (pixelSize > 2)
- {
- SetIfBkColor(fBackColor);
- if (this->IsDimmed())
- SetIfColor(kMediumGray);
- else
- SetIfColor(fForeColor);
- }
- MoveTo (localBox.left, localBox.top + theFontInfo.ascent);
- DrawString(s);
- }
-
- } // T3DCheckBox::DrawBoxText
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::DrawBox
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DCheckBox::DrawBox()
- {
- CRect qdBox;
- short pixelSize;
- CGraphicsState rememberGState;
-
- this->ViewToQDRect(fDrawBox, qdBox);
-
- CDrawPerDevice device(qdBox);
- while (device.NextDevice (pixelSize))
- {
- // Draw the 3D effect if we're in non B & W
- if (pixelSize > 2)
- {
- if (!this->IsDimmed())
- {
- SetIfColor(gRGBWhite);
- MoveTo(qdBox.left+1, qdBox.bottom-1);
- LineTo(qdBox.right-1, qdBox.bottom-1);
- LineTo(qdBox.right-1, qdBox.top+1);
-
- SetIfColor(kMediumLightGray);
- MoveTo(qdBox.right, qdBox.top);
- LineTo(qdBox.left, qdBox.top);
- LineTo(qdBox.left, qdBox.bottom);
- SetIfColor(fForeColor);
- }
- else
- SetIfColor(kMediumGray);
- }
- else
- SetIfColor(gRGBBlack);
-
- // Now draw the regular check box
- InsetRect(qdBox, 1, 1);
- FrameRect(qdBox);
- InsetRect(qdBox, -1, -1);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::DrawCheck
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DCheckBox::DrawCheck()
- {
- CRect qdBox;
- CGraphicsState rememberGState;
-
- this->ViewToQDRect(fDrawBox, qdBox);
-
- InsetRect(qdBox, 2, 2);
- SetIfBkColor(gRGBWhite);
- EraseRect(qdBox);
-
- // Draw the check if we're on
- if (this->IsOn())
- {
- short pixelSize;
- CDrawPerDevice device(qdBox);
- while (device.NextDevice (pixelSize))
- {
- if (pixelSize > 2)
- if (this->IsDimmed())
- SetIfColor(kMediumGray);
-
- MoveTo(qdBox.left-1, qdBox.bottom);
- LineTo(qdBox.right-1, qdBox.top);
- MoveTo(qdBox.left, qdBox.top);
- LineTo(qdBox.right, qdBox.bottom);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox::DrawCheck
- // Override because we don't want the Inherited method, which uses the CDEF
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DCheckBox::InstallColor(const CRGBColor& theColor, Boolean redraw)
- {
- fForeColor = theColor;
- if (redraw)
- this->ForceRedraw();
- }
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::Initialize
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- #undef Inherited
- #define Inherited TRadio
- DefineClass(T3DRadio, TRadio);
-
- void T3DRadio::Initialize () // OVERRIDE
- {
- fBackColor = kLightGray;
- fForeColor = gRGBBlack;
- fDrawBox = VRect(2, 0, 14, 12); // A radio button is 12x12
-
- } // T3DRadio::Initialize
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::DoPostCreate
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void T3DRadio::DoPostCreate (TDocument *itsDocument) // OVERRIDE
- {
- VRect theRect;
- TDrawingEnvironment *environment;
-
- Inherited::DoPostCreate (itsDocument);
-
- // If we have a drawing environment, use it!
- if (environment = this->GetDrawingEnvironment())
- {
- this->SetBackColor(environment->fBackgroundColor);
- this->InstallColor(environment->fForegroundColor, false);
- }
-
- // Center the button vertically
- this->ControlArea(theRect);
- long height = theRect.bottom - theRect.top;
- height -= 12;
- long top = height / 2;
- fDrawBox.top += top;
- fDrawBox.bottom += top;
-
- } // T3DRadio::DoPostCreate
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::I3DRadio
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void T3DRadio::I3DRadio (TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, const CStr255& itsLabel,
- Boolean isTurnedOn)
- {
- VRect theRect;
- TDrawingEnvironment *environment;
-
- this->IRadio (itsSuperView, itsLocation, itsSize,
- itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn);
-
- // If we have a drawing environment, use it!
- if (environment = this->GetDrawingEnvironment())
- {
- this->SetBackColor(environment->fBackgroundColor);
- this->InstallColor(environment->fForegroundColor, false);
- }
-
- // Center the button vertically
- this->ControlArea(theRect);
- long height = theRect.bottom - theRect.top;
- height -= 12;
- long top = height / 2;
- fDrawBox.top += top;
- fDrawBox.bottom += top;
-
- } // T3DRadio::I3DRadio
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::Clone
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- TObject* T3DRadio::Clone () // OVERRIDE
- {
- T3DRadio* aClonedRadio = (T3DRadio *)(Inherited::Clone ());
-
- aClonedRadio->fBackColor = fBackColor;
- aClonedRadio->fForeColor = fForeColor;
-
- return aClonedRadio;
-
- } // T3DRadio::Clone
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::Free
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlClose
-
- void T3DRadio::Free () // OVERRIDE
- {
- Inherited::Free ();
-
- } // T3DRadio::Free
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DRadio::Draw (const VRect& /*area*/)
- {
- VRect theRect;
- CRect qdArea;
- CStr255 label;
- CGraphicsState rememberGState;
-
- this->ControlArea(theRect);
- this->ViewToQDRect(theRect, qdArea);
-
- this->DrawBox();
- this->DrawCheck();
-
- // Draw the button text 4 pixels to the right of the button
- this->GetText (label);
- CRect textBox = qdArea;
- textBox.left += (short) fDrawBox.right + 4;
- this->DrawBoxText (label, textBox, false);
-
- } // T3DRadio::Draw
-
- //----------------------------------------------------------------------------------------
- // T3DButton::DoMouseCommand
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlSelCommand
-
- void T3DRadio::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* ,
- CPoint) // override
- {
- TControlTracker * aControlTracker = new TControlTracker;
- aControlTracker->IControlTracker(this, theMouse);
- this->PostCommand(aControlTracker);
- } // T3DRadio::DoMouseCommand
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::TrackMouse
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlSelCommand
-
- void T3DRadio::TrackMouse(TrackPhase aTrackPhase,
- VPoint& ,
- // anchorPoint
- VPoint& ,
- // previousPoint
- VPoint& nextPoint,
- Boolean) // OVERRIDE
- {
- Boolean state = false;
-
- if (!this->IsDimmed())
- {
- switch(aTrackPhase)
- {
- case trackBegin:
- state = fHilite;
- this->HiliteState(true, kRedraw);
- break;
- case trackContinue:
- if (this->ContainsMouse(nextPoint))
- this->HiliteState(true, kRedraw);
- else
- this->HiliteState(state, kRedraw);
- break;
- case trackEnd:
- if (this->ContainsMouse(nextPoint))
- {
- this->HiliteState(false, this->IsOn());
- this->HandleEvent(fEventNumber, this, NULL);
- }
- break;
- }
- }
- } // T3DRadio::TrackMouse
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::SetLongVal:
- // Override the way the control works so that we don't call the CDEF
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DRadio::SetLongVal(VCoordinate itsVal, Boolean /*redraw*/)
- {
- itsVal = Max(fLongMin, Min(itsVal, fLongMax));
- if (itsVal != fLongVal)
- {
- fLongVal = itsVal;
- CRect tempRect;
- this->ViewToQDRect(fDrawBox, tempRect);
-
- // Make a region for the inside of the button to invalidate
- CTemporaryRegion region;
- InsetRect(tempRect, 1,1);
- OpenRgn();
- FrameOval(tempRect);
- CloseRgn(region);
- this->InvalidateRegion(region);
- }
- } // T3DRadio::SetLongVal
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::HiliteState:
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void T3DRadio::HiliteState(Boolean state,Boolean redraw)
- {
- if (state != fHilite)
- {
- fHilite = state;
- if (state) // hilite adorner draws the hilite state
- this->AddAdorner(gHiliteAdorner, kAdornLast - 5, kDontRedraw);
- else
- this->DeleteAdorner(gHiliteAdorner, kDontRedraw);
- if (redraw)
- this->Hilite();
- }
- } // T3DRadio::HiliteState
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::DimState:
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void T3DRadio::DimState(Boolean state, Boolean redraw)
- {
- if (state != fDimmed)
- {
- fDimmed = state;
- if (state) // dim adorner draws the dim state
- this->AddAdorner(gDimAdorner, kAdornLast - 10, kDontRedraw);
- else
- this->DeleteAdorner(gDimAdorner, kDontRedraw);
- if (redraw)
- this->DrawContents(); // Draw change immediately
- }
- } // T3DRadio::DimState
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::Hilite
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DRadio::Hilite () // OVERRIDE
- {
- VRect area;
- CRect qdArea, qdBox;
- CGraphicsState rememberGState;
-
- #if qDebug
- this->AssumeFocused ();
- #endif
-
- this->ControlArea (area);
- this->ViewToQDRect (area, qdArea);
- this->ViewToQDRect(fDrawBox, qdBox);
-
- CPenNormal();
- if (fHilite)
- {
- InsetRect(qdBox, 1, 1);
- FrameOval(qdBox);
- InsetRect(qdBox, 1,1);
-
- // Erase the content of the oval
- SetIfBkColor(fBackColor);
- if (this->IsOn())
- {
- PenPat(&qd.white);
- FrameOval(qdBox);
- }
- else
- EraseOval(qdBox);
- }
- else
- this->DrawCheck();
- } // T3DRadio::Hilite
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::Dim
- //----------------------------------------------------------------------------------------
- #pragma segment ControlRes
-
- void T3DRadio::Dim () // OVERRIDE
- {
- VRect area;
- CRect qdArea;
- CGraphicsState rememberGState;
-
- this->ControlArea (area);
- area.left += fDrawBox.right;
- this->ViewToQDRect (area, qdArea);
-
- short pixelSize;
- CDrawPerDevice device(qdArea);
- while (device.NextDevice (pixelSize))
- {
- // Do the normal gray pattern thing if we're in B & W
- if (pixelSize < 2)
- {
- #if qDebug
- this->AssumeFocused ();
- #endif
-
- InsetRect (qdArea, 1, 1);
-
- PenPat (&qd.gray);
- PenMode (patBic);
- PaintRect (qdArea);
- InsetRect (qdArea, -1, -1);
- }
- }
- } // T3DRadio::Dim
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::DrawBoxText
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DRadio::DrawBoxText (const CStr255& s, const CRect& box, Boolean preferOutline)
- {
- FontInfo theFontInfo;
- CRect localBox = box;
- CRect qdArea;
- CGraphicsState rememberGState;
-
- CWhileOutlinePreferred setOP (preferOutline);
-
- short textHeight = MAGetFontInfo (theFontInfo);
- CPoint boxSize = localBox.GetSize ();
-
- // Center the text horizontally
- localBox.top += (boxSize.v - textHeight) / 2;
- MoveTo (localBox.left, localBox.top + theFontInfo.ascent);
-
- short pixelSize;
- CDrawPerDevice device(localBox);
- while (device.NextDevice (pixelSize))
- {
- // If we're dimmed, draw in gray, else draw in the fore color
- if (pixelSize > 2)
- {
- SetIfBkColor(fBackColor);
- if (this->IsDimmed())
- // Draw the text in gray if we can
- SetIfColor(kMediumGray);
- else
- SetIfColor(fForeColor);
- }
- MoveTo (localBox.left, localBox.top + theFontInfo.ascent);
- DrawString (s); // This would be faster if we did StringWidth and DrawChar...
- }
-
- } // T3DRadio::DrawBoxText
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::DrawBox
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DRadio::DrawBox()
- {
- CRect qdBox;
- CGraphicsState rememberGState;
-
- this->ViewToQDRect(fDrawBox, qdBox);
-
- short pixelSize;
- CDrawPerDevice device(qdBox);
- while (device.NextDevice (pixelSize))
- {
- if (pixelSize > 2)
- {
- if (this->IsDimmed())
- SetIfColor(kMediumGray);
- else
- SetIfColor(fForeColor);
- }
- FrameOval(qdBox);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::DrawCheck
- // This actually draws a dot, but I wanted to keep it similar to the check box
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DRadio::DrawCheck()
- {
- CRect qdBox;
- short pixelSize;
- CGraphicsState rememberGState;
-
- this->ViewToQDRect(fDrawBox, qdBox);
-
- // First erase the oval
- InsetRect(qdBox, 1, 1);
- if (this->IsDimmed())
- SetIfBkColor(fBackColor);
- else
- SetIfBkColor(gRGBWhite);
- EraseOval(qdBox);
- InsetRect(qdBox, -1, -1);
-
- // Check to see if we're on
- if (this->IsOn())
- {
- CDrawPerDevice device(qdBox);
- while (device.NextDevice (pixelSize))
- {
- // This takes some pretty subtle work
- if (pixelSize > 2)
- {
- if (!this->IsDimmed())
- {
- SetIfColor(kLightGray);
- MoveTo(qdBox.left + 9, qdBox.top + 5);
- LineTo(qdBox.left + 9, qdBox.top + 7);
- MoveTo(qdBox.left + 5, qdBox.top + 9);
- LineTo(qdBox.left + 7, qdBox.top + 9);
-
- SetIfColor(kLightGray2);
- MoveTo(qdBox.left + 3, qdBox.top + 9);
- LineTo(qdBox.left + 4, qdBox.top + 9);
- MoveTo(qdBox.left + 9, qdBox.top + 3);
- LineTo(qdBox.left + 9, qdBox.top + 4);
-
- SetIfColor(kLightGray4);
- MoveTo(qdBox.left + 2, qdBox.top + 9);
- LineTo(qdBox.left + 2, qdBox.top + 8);
- LineTo(qdBox.left + 3, qdBox.top + 8);
- MoveTo(qdBox.left + 8, qdBox.top + 3);
- LineTo(qdBox.left + 8, qdBox.top + 2);
- LineTo(qdBox.left + 9, qdBox.top + 2);
-
- SetIfColor(kMediumLightGray);
- MoveTo(qdBox.left + 2, qdBox.top + 7);
- LineTo(qdBox.left + 2, qdBox.top + 4);
- LineTo(qdBox.left + 4, qdBox.top + 2);
- LineTo(qdBox.left + 7, qdBox.top + 2);
-
- SetIfColor(kMediumGray);
- MoveTo(qdBox.left + 1, qdBox.top + 7);
- LineTo(qdBox.left + 1, qdBox.top + 4);
- LineTo(qdBox.left + 4, qdBox.top + 1);
- LineTo(qdBox.left + 7, qdBox.top + 1);
- MoveTo(qdBox.left + 2, qdBox.top + 2); // this is faster
- LineTo(qdBox.left + 2, qdBox.top + 2); // than SetCPixel
- SetIfColor(gRGBBlack);
- }
- else
- SetIfColor(kMediumGray);
- }
- else
- SetIfColor(gRGBBlack);
- InsetRect(qdBox, 3,3);
- FillOval(qdBox, &qd.black);
- InsetRect(qdBox, -3, -3);
- }
- }
- // This is how we look when we're off
- else
- {
- // Off and dimmed takes some work, off and not dimmed takes no work
- if (!this->IsDimmed())
- {
- CDrawPerDevice device(qdBox);
- while (device.NextDevice (pixelSize))
- {
- if (pixelSize > 2)
- {
- SetIfColor(kLightGray);
- MoveTo(qdBox.left + 6, qdBox.top + 2);
- LineTo(qdBox.left + 3, qdBox.top + 5);
- MoveTo(qdBox.left + 4, qdBox.top + 5);
- LineTo(qdBox.left + 7, qdBox.top + 2);
- MoveTo(qdBox.left + 3, qdBox.top + 5);
- LineTo(qdBox.left + 3, qdBox.top + 7);
-
- SetIfColor(kLightGray2);
- MoveTo(qdBox.left + 3, qdBox.top + 8);
- LineTo(qdBox.left + 4, qdBox.top + 8);
- LineTo(qdBox.left + 4, qdBox.top + 6);
- LineTo(qdBox.left + 6, qdBox.top + 6);
- LineTo(qdBox.left + 6, qdBox.top + 4);
- LineTo(qdBox.left + 7, qdBox.top + 4);
- LineTo(qdBox.left + 7, qdBox.top + 3);
- LineTo(qdBox.left + 8, qdBox.top + 3);
- LineTo(qdBox.left + 8, qdBox.top + 2);
- MoveTo(qdBox.left + 5, qdBox.top + 5);
- LineTo(qdBox.left + 5, qdBox.top + 5);
- MoveTo(qdBox.left + 7, qdBox.top + 5);
- LineTo(qdBox.left + 7, qdBox.top + 5);
- MoveTo(qdBox.left + 5, qdBox.top + 7);
- LineTo(qdBox.left + 5, qdBox.top + 7);
-
- SetIfColor(kLightGray4);
- MoveTo(qdBox.left + 3, qdBox.top + 9);
- LineTo(qdBox.left + 5, qdBox.top + 9);
- LineTo(qdBox.left + 5, qdBox.top + 8);
- LineTo(qdBox.left + 6, qdBox.top + 8);
- LineTo(qdBox.left + 6, qdBox.top + 7);
- LineTo(qdBox.left + 7, qdBox.top + 7);
- LineTo(qdBox.left + 7, qdBox.top + 6);
- LineTo(qdBox.left + 8, qdBox.top + 6);
- LineTo(qdBox.left + 8, qdBox.top + 4);
-
- SetIfColor(kMediumLightGray);
- MoveTo(qdBox.left + 6, qdBox.top + 9);
- LineTo(qdBox.left + 7, qdBox.top + 9);
- LineTo(qdBox.left + 7, qdBox.top + 8);
- LineTo(qdBox.left + 8, qdBox.top + 8);
- LineTo(qdBox.left + 8, qdBox.top + 7);
- LineTo(qdBox.left + 9, qdBox.top + 7);
- LineTo(qdBox.left + 9, qdBox.top + 2);
-
- SetIfColor(kMediumGray);
- MoveTo(qdBox.left + 4, qdBox.top + 10);
- LineTo(qdBox.left + 7, qdBox.top + 10);
- MoveTo(qdBox.left + 8, qdBox.top + 9);
- LineTo(qdBox.left + 9, qdBox.top + 9);
- LineTo(qdBox.left + 9, qdBox.top + 8);
- MoveTo(qdBox.left + 10, qdBox.top + 7);
- LineTo(qdBox.left + 10, qdBox.top + 4);
-
- }
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // T3DRadio::InstallColor
- // Override because we don't want the Inherited method, which uses the CDEF
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DRadio::InstallColor(const CRGBColor& theColor, Boolean redraw)
- {
- fForeColor = theColor;
- if (redraw)
- this->ForceRedraw();
- }
-
- //----------------------------------------------------------------------------------------
- // CLASS: T3DButton
- // A 3D version of our old friend the Button
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // T3DButton::Initialize
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- #undef Inherited
- #define Inherited TButton
- DefineClass(T3DButton, Inherited);
-
- void T3DButton::Initialize () // OVERRIDE
- {
- f3DAdorner = NULL;
- fHilitedTextColor = gRGBBlack;
-
- } // T3DButton::Initialize
-
- //----------------------------------------------------------------------------------------
- // T3DButton::DoPostCreate
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void T3DButton::DoPostCreate (TDocument *itsDocument) // OVERRIDE
- {
- Inherited::DoPostCreate (itsDocument);
-
- if (f3DAdorner == NULL)
- this->CreateButtonAdorner ();
-
- } // T3DButton::DoPostCreate
-
- //----------------------------------------------------------------------------------------
- // T3DButton::I3DButton
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void T3DButton::I3DButton (TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const CStr255& itsLabel)
- {
- this->IButton(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel);
-
- // • If we are being built procedurally then build the adorner
- if (f3DAdorner == NULL)
- this->CreateButtonAdorner ();
-
- } // T3DButton::I3DButton
-
- //----------------------------------------------------------------------------------------
- // T3DButton::Clone
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- TObject* T3DButton::Clone () // OVERRIDE
- {
- T3DButton* aClonedButton = (T3DButton *)(Inherited::Clone ());
- aClonedButton->fHilitedTextColor = fHilitedTextColor;
- aClonedButton->CreateButtonAdorner();
-
- return aClonedButton;
-
- } // T3DButton::Clone
-
- //----------------------------------------------------------------------------------------
- // T3DButton::Free
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlClose
-
- void T3DButton::Free () // OVERRIDE
- {
- Inherited::Free ();
-
- } // T3DButton::Free
-
- //----------------------------------------------------------------------------------------
- // T3DButton::DoMouseCommand
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DButton::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* ,
- CPoint) // override
- {
- TControlTracker * aControlTracker = new TControlTracker;
- aControlTracker->IControlTracker(this, theMouse);
- this->PostCommand(aControlTracker);
- } // TControl::DoMouseCommand
-
- //----------------------------------------------------------------------------------------
- // T3DButton::TrackMouse
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlSelCommand
-
- void T3DButton::TrackMouse(TrackPhase aTrackPhase,
- VPoint& ,
- // anchorPoint
- VPoint& ,
- // previousPoint
- VPoint& nextPoint,
- Boolean) // OVERRIDE
- {
- Boolean state = false;
-
- if (!this->IsDimmed())
- {
- switch(aTrackPhase)
- {
- case trackBegin:
- state = fHilite;
- this->HiliteState(true, kRedraw);
- break;
- case trackContinue:
- if (this->ContainsMouse(nextPoint))
- this->HiliteState(true, kRedraw);
- else
- this->HiliteState(state, kRedraw);
- break;
- case trackEnd:
- if (this->ContainsMouse(nextPoint))
- {
- this->HiliteState(false, kRedraw);
- this->HandleEvent(fEventNumber, this, NULL);
- }
- break;
- }
- }
- } // T3DButton::TrackMouse
-
- //----------------------------------------------------------------------------------------
- // T3DButton::HiliteState:
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void T3DButton::HiliteState(Boolean state,Boolean redraw)
- {
- if (state != fHilite)
- {
- fHilite = state;
- if (state) // hilite adorner draws the hilite state
- this->AddAdorner(gHiliteAdorner, kAdornLast - 5, kDontRedraw);
- else
- this->DeleteAdorner(gHiliteAdorner, kDontRedraw);
- if (redraw && this->IsDrawable())
- this->Hilite();
- }
- } // T3DButton::HiliteState
-
- //----------------------------------------------------------------------------------------
- // T3DButton::DimState:
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void T3DButton::DimState(Boolean state, Boolean redraw)
- {
- if (state != fDimmed)
- {
- fDimmed = state;
- if (state) // dim adorner draws the dim state
- this->AddAdorner(gDimAdorner, kAdornLast - 10, kDontRedraw);
- else
- this->DeleteAdorner(gDimAdorner, kDontRedraw);
- if (redraw)
- this->DrawContents(); // Draw change immediately
- }
- } // T3DButton::DimState
-
- //----------------------------------------------------------------------------------------
- // T3DButton::CreateButtonAdorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void T3DButton::CreateButtonAdorner ()
- {
- // • Add the Button Adorner
- T3DTextButtonAdorner* adorner = new T3DTextButtonAdorner;
- adorner->I3DTextButtonAdorner (kFreeOnDeletion);
- f3DAdorner = adorner;
-
- this->AddAdorner (adorner, kAdornFirst, kDontInvalidate);
-
- } // T3DButton::CreateButtonAdorner
-
- //----------------------------------------------------------------------------------------
- // T3DButton::DrawBoxText
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DButton::DrawBoxText ( const CStr255& s,
- const CRect& box,
- Boolean preferOutline)
- {
- FontInfo theFontInfo;
- CRect qdArea, localBox = box;
- CGraphicsState remember;
-
- CWhileOutlinePreferred setOP (preferOutline);
-
- short textHeight = MAGetFontInfo (theFontInfo);
- CPoint boxSize = localBox.GetSize ();
-
- // Center the text in the button
- localBox.left += (boxSize.h - StringWidth (s)) / 2;
- localBox.top += (boxSize.v - textHeight) / 2;
-
- this->ViewToQDRect (localBox, qdArea);
- short pixelSize;
- CDrawPerDevice device(qdArea);
- while (device.NextDevice (pixelSize))
- {
- if (pixelSize >= 4)
- {
- // If we're non B & W and we're dimmed, draw in gray text
- if (this->IsDimmed())
- SetIfColor(kMediumGray);
- // If we're hilited, use the hilite text color
- else if (fHilite)
- SetIfColor(fHilitedTextColor);
- }
- MoveTo (localBox.left, localBox.top + theFontInfo.ascent);
- DrawString (s);
- }
-
- } // T3DButton::DrawBoxText
-
- //----------------------------------------------------------------------------------------
- // T3DButton::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DButton::Draw (const VRect& /*area*/) // OVERRIDE
- {
- VRect theRect;
- CRect qdArea;
- CStr255 label;
-
- this->ControlArea (theRect);
- this->ViewToQDRect (theRect, qdArea);
-
- this->GetText (label);
-
- // Just draw the text. The adorner takes care of the 3D stuff
- DrawBoxText (label, qdArea, false);
-
- } // T3DButton::Draw
-
- //----------------------------------------------------------------------------------------
- // T3DButton::Hilite
- //----------------------------------------------------------------------------------------
- #pragma segment ControlRes
-
- void T3DButton::Hilite () // OVERRIDE
- {
- VRect area;
- CRect qdArea;
- CGraphicsState rememberGState;
-
- #if qDebug
- this->AssumeFocused ();
- #endif
-
- this->ControlArea (area);
- this->ViewToQDRect (area, qdArea);
-
- short pixelSize;
- CDrawPerDevice device(qdArea);
- // We use some funky logic here because of the way the 3d adorner works.
- // For 4, 8 and above, we draw one way. Otherwise we draw another way
- // See the adorner code for more info
- while (device.NextDevice (pixelSize))
- {
- if (pixelSize < 4)
- {
- // We need to draw the text BEFORE the adorner if we're B & W
- if (fHilite)
- {
- this->Draw (area);
- f3DAdorner->Draw (this, area);
- }
- else
- {
- f3DAdorner->Draw(this, area);
- this->Draw(area);
- }
- }
- else
- {
- // We need to draw the text AFTER the adorner for better than B & W
- f3DAdorner->Draw(this, area);
- this->Draw(area);
- }
- }
- } // T3DButton::Hilite
-
- //----------------------------------------------------------------------------------------
- // T3DButton::Dim
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DButton::Dim () // OVERRIDE
- {
- VRect area;
- CRect qdArea;
- CGraphicsState rememberGState;
-
- #if qDebug
- this->AssumeFocused ();
- #endif
-
- this->ControlArea (area);
- this->ViewToQDRect (area, qdArea);
- InsetRect (qdArea, 1, 1);
-
- short pixelSize;
- CDrawPerDevice device(qdArea);
- while (device.NextDevice (pixelSize))
- {
- // The old fashioned way is to use a gray pattern to dim
- if (pixelSize < 2)
- {
- #if qDebug
- this->AssumeFocused ();
- #endif
-
- InsetRect (qdArea, 1, 1);
-
- PenPat (&qd.gray);
- PenMode (patBic);
- PaintRect (qdArea);
- InsetRect (qdArea, -1, -1);
- }
- }
-
- } // T3DButton::Dim
-
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner
- // This is an auxiliary adorner for T3DButtons
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner::I3DTextButtonAdorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- #undef Inherited
- #define Inherited TAdorner
- DefineClass(T3DTextButtonAdorner, Inherited);
-
- void T3DTextButtonAdorner::I3DTextButtonAdorner ( Boolean freeOnDeletion)
- {
- // • Call our superclass to complete initialization
- this->IAdorner (k3DTextButtonAdorner,freeOnDeletion);
-
- } // T3DTextButtonAdorner::I3DTextButtonAdorner
-
- //----------------------------------------------------------------------------------------
- // •• DRAWING
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner::Draw
- //----------------------------------------------------------------------------------------
- //
- // This overridden draw method handles the drawing of the buttons border and then
- // branches to the appropriate appropriate method to draw the buttons contents, based
- // on the bit depth of the device being drawn to. Currently this method supports 1, 4,
- // and 8 bit or more devices.
-
- #pragma segment A3DControlRes
-
- void T3DTextButtonAdorner::Draw ( TView* itsView, const VRect& /*area*/)
- {
- VRect theRect;
- CRect qdArea;
- short pixelSize;
- CRGBColor color;
-
- // • Instantiate a stack based object that saves our graphic state
- CGraphicsState aGraphicsState;
-
- // • Coerce the view to a control and then get its QD area
- TControl* theControl = (TControl*)itsView;
- theControl->ControlArea (theRect);
- theControl->ViewToQDRect (theRect, qdArea);
-
- // • Instantiate the stack based object that handles the per device clipping
- // the area is passed in so that the object can do clipping from it
- CDrawPerDevice device (qdArea);
-
- // • We will cycle through all of the devices, drawing will be handle based on
- // the pixel size for each device
- while (device.NextDevice (pixelSize))
- {
-
- // • Draw the button with full colors
- if (pixelSize >= 8)
- {
- // • First step is to setup the appropriate gray fill color
- if (theControl->fHilite)
- color = kMediumGray;
- else if (((TButton *)itsView)->IsDimmed())
- color = kLightGray;
- else
- color = kLightGray2;
-
- // • Fill the round rect with the color
- SetIfColor (color);
- PaintRoundRect (qdArea, kOvalWidth, kOvalHeight);
-
- // • Frame button with a black border or gray if it's dimmed
- if (((TButton *)itsView)->IsDimmed())
- SetIfColor(kMediumGray);
- else
- SetIfColor (gRGBBlack);
- this->Frame (qdArea);
-
- // • Inset the area in preparartion for the drawing of the buttons content
- InsetRect (qdArea, 1, 1);
-
- // • Draw the button assuming 8 bit or better color
- // But don't draw any 3D if we're dimmed
- if (!((TButton *)itsView)->IsDimmed())
- this->Draw8Bit (qdArea, theControl->fHilite);
-
- InsetRect (qdArea, -1, -1);
-
- }
- else if (pixelSize == 4) // • Draw with only 16 colors
- {
-
- // • First step is to setup the appropriate gray fill color
- if (theControl->fHilite)
- SetRGBColor (color, kRGB4BitGray2, kRGB4BitGray2, kRGB4BitGray2);
- else if (((TButton *)itsView)->IsDimmed())
- color = kLightGray;
- else
- SetRGBColor (color, kRGB4BitGray1, kRGB4BitGray1, kRGB4BitGray1);
-
- // • Fill the round rect with the color
- SetIfColor (color);
- PaintRoundRect (qdArea, kOvalWidth, kOvalHeight);
-
- // • Frame button with a black border or gray if we're dimmed
- if (((TButton *)itsView)->IsDimmed())
- SetIfColor(kMediumGray);
- else
- SetIfColor (gRGBBlack);
- this->Frame (qdArea);
-
- // • Inset the area in preparartion for the drawing of the buttons content
- InsetRect (qdArea, 1, 1);
-
- // • For now we will draw the 1 bit style for 4 bit, but this should be
- // replaced with a 4 bit algorithm which will give you 3 shades of gray
- // But don't draw any 3D if we're dimmed
- if (!((TButton *)itsView)->IsDimmed())
- this->Draw4Bit (qdArea, theControl->fHilite);
-
- InsetRect (qdArea, -1, -1);
-
- }
- else if (pixelSize < 4) // • Draw with 4 colors or less (no grays)
- {
- // • We are hiliting so we need to invert the whole thing
- if (theControl->fHilite)
- {
- // • First we paint the inside white
- InvertRoundRect (qdArea, kOvalWidth, kOvalHeight);
-
- // • Frame button with a black border
- SetIfColor (gRGBBlack);
- this->Frame (qdArea);
- }
- else
- {
- // • First we erase the entire area
- SetIfBkColor (gRGBWhite);
- EraseRoundRect (qdArea, kOvalWidth, kOvalHeight);
-
- // • Frame button with a black border
- SetIfColor (gRGBBlack);
- this->Frame (qdArea);
- }
- }
- }
-
- } // T3DTextButtonAdorner::Draw
-
- //----------------------------------------------------------------------------------------
- // •• PRIVATE DRAWING
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner::Draw8Bit
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DTextButtonAdorner::Draw8Bit (const CRect& rect, Boolean hilite)
- {
- CRect insetArea;
- CRect controlArea;
- CRGBColor color;
- CRGBColor light;
- CRGBColor dark;
-
- // • Make a copy of the rect passed in
- controlArea = rect;
-
- // • Save off the area passed in
- insetArea = rect;
-
- // • Draw the hilited button
- if (hilite)
- {
- // • Outside edge of left top shadow
- SetRGBColor (color, kRGB8BitGray9, kRGB8BitGray9, kRGB8BitGray9);
- SetIfColor (color);
- MoveTo (controlArea.left, controlArea.bottom - 3);
- LineTo (controlArea.left, controlArea.top + 2);
- MoveTo (controlArea.left + 2, controlArea.top);
- LineTo (controlArea.right - 3, controlArea.top);
-
- // • Outside edge of bottom right shadow
- SetRGBColor (color, kRGB8BitGray3, kRGB8BitGray3, kRGB8BitGray3);
- SetIfColor (color);
- MoveTo (controlArea.left + 2, controlArea.bottom - 1);
- LineTo (controlArea.right - 3, controlArea.bottom - 1);
- MoveTo (controlArea.right - 1, controlArea.bottom - 3);
- LineTo (controlArea.right - 1, controlArea.top + 2);
-
- // • Inset our rectangle as we move to the next level
- InsetRect (controlArea, 1, 1);
-
- // • Inside edge of left top shadow
- SetRGBColor (color, kRGB8BitGray8, kRGB8BitGray8, kRGB8BitGray8);
- SetIfColor (color);
- MoveTo (controlArea.left, controlArea.bottom - 2);
- LineTo (controlArea.left, controlArea.top + 1);
- MoveTo (controlArea.left + 1, controlArea.top);
- LineTo (controlArea.right - 2, controlArea.top);
-
- // • Inside edge of bottom right shadow
- color = kMediumLightGray;
- SetIfColor (color);
- MoveTo (controlArea.left + 1, controlArea.bottom - 1);
- LineTo (controlArea.right - 2, controlArea.bottom - 1);
- MoveTo (controlArea.right - 1, controlArea.bottom - 2);
- LineTo (controlArea.right - 1, controlArea.top + 1);
-
- // •• Now draw the corners
- // • TopLeft 1
- SetRGBColor (light, kRGB8BitGray8, kRGB8BitGray8, kRGB8BitGray8);
- SetRGBColor (dark, kRGB8BitGray9, kRGB8BitGray9, kRGB8BitGray9);
- this->TopLeftCorner (insetArea, light, dark, hilite);
-
- // • TopRight 2
- SetRGBColor (light, kRGB8BitGray8, kRGB8BitGray8, kRGB8BitGray8);
- SetRGBColor (dark, kRGB8BitGray9, kRGB8BitGray9, kRGB8BitGray9);
- this->TopRightCorner (insetArea, light, dark, hilite);
-
- // • BotLeft 3
- // • Colors same as previous corner
- this->BotLeftCorner (insetArea, light, dark, hilite);
-
- // • BotRight 4
- SetRGBColor (light, kRGB8BitGray3, kRGB8BitGray3, kRGB8BitGray3);
- dark = kMediumLightGray;
- this->BotRightCorner (insetArea, light, dark, hilite);
-
- }
- else // • Draw the unhilited button
- {
- // • Outside edge of bottom right shadow
- SetRGBColor (color, kRGB8BitGray8, kRGB8BitGray8, kRGB8BitGray8);
- SetIfColor (color);
- MoveTo (controlArea.left + 2, controlArea.bottom - 1);
- LineTo (controlArea.right - 3, controlArea.bottom - 1);
- MoveTo (controlArea.right - 1, controlArea.bottom - 3);
- LineTo (controlArea.right - 1, controlArea.top + 2);
-
- // • Inset our rectangle as we move to the next level
- InsetRect (controlArea, 1, 1);
-
- // • Light on edge of button - light source edge
- SetIfColor (gRGBWhite);
- MoveTo (controlArea.left, controlArea.bottom - 2);
- LineTo (controlArea.left, controlArea.top + 1);
- MoveTo (controlArea.left + 1, controlArea.top);
- LineTo (controlArea.right - 2, controlArea.top);
-
- // • Inside edge of bottom right shadow
- color = kMediumGray;
- SetIfColor (color);
- MoveTo (controlArea.left + 1, controlArea.bottom - 1);
- LineTo (controlArea.right - 2, controlArea.bottom - 1);
- MoveTo (controlArea.right - 1, controlArea.bottom - 2);
- LineTo (controlArea.right - 1, controlArea.top + 1);
-
- // •• Now draw the corners
- // • TopLeft 1
- this->TopLeftCorner (insetArea, gRGBWhite, gRGBWhite, hilite);
-
- // • TopRight 2
- light = kLightGray4;
- this->TopRightCorner (insetArea, light, light, hilite);
-
- // • BotLeft 3
- // • Colors same as previous corner
- this->BotLeftCorner (insetArea, light, light, hilite);
-
- // • BotRight 4
- light = kMediumGray;
- SetRGBColor (dark, kRGB8BitGray8, kRGB8BitGray8, kRGB8BitGray8);
- this->BotRightCorner (insetArea, light, dark, hilite);
-
- }
-
- } // T3DTextButtonAdorner::Draw8Bit
-
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner::Draw4Bit
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DTextButtonAdorner::Draw4Bit (const CRect& rect, Boolean hilite)
- {
- CRect insetArea;
- CRect controlArea;
- CRGBColor color;
- CRGBColor light;
- CRGBColor dark;
-
- // • Make a copy of the rect passed in
- controlArea = rect;
-
- // • Save off the area passed in
- insetArea = rect;
-
- // • Draw the hilited button
- if (hilite)
- {
- // • Outside edge of left top shadow
- SetRGBColor (color, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3);
- SetIfColor (color);
- MoveTo (controlArea.left, controlArea.bottom - 3);
- LineTo (controlArea.left, controlArea.top + 2);
- MoveTo (controlArea.left + 2, controlArea.top);
- LineTo (controlArea.right - 3, controlArea.top);
-
- // • Outside edge of bottom right shadow
- SetRGBColor (color, kRGB4BitGray1, kRGB4BitGray1, kRGB4BitGray1);
- SetIfColor (color);
- MoveTo (controlArea.left + 2, controlArea.bottom - 1);
- LineTo (controlArea.right - 3, controlArea.bottom - 1);
- MoveTo (controlArea.right - 1, controlArea.bottom - 3);
- LineTo (controlArea.right - 1, controlArea.top + 2);
-
- // • Inset our rectangle as we move to the next level
- InsetRect (controlArea, 1, 1);
-
- // • Inside edge of left top shadow
- SetRGBColor (color, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3);
- SetIfColor (color);
- MoveTo (controlArea.left, controlArea.bottom - 2);
- LineTo (controlArea.left, controlArea.top + 1);
- MoveTo (controlArea.left + 1, controlArea.top);
- LineTo (controlArea.right - 2, controlArea.top);
-
- // • Inside edge of bottom right shadow
- SetRGBColor (color, kRGB4BitGray1, kRGB4BitGray1, kRGB4BitGray1);
- SetIfColor (color);
- MoveTo (controlArea.left + 1, controlArea.bottom - 1);
- LineTo (controlArea.right - 2, controlArea.bottom - 1);
- MoveTo (controlArea.right - 1, controlArea.bottom - 2);
- LineTo (controlArea.right - 1, controlArea.top + 1);
-
- // •• Now draw the corners
- // • TopLeft 1
- SetRGBColor (light, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3);
- SetRGBColor (dark, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3);
- this->TopLeftCorner (insetArea, light, dark, hilite);
-
- // • TopRight 2
- SetRGBColor (light, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3);
- SetRGBColor (dark, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3);
- this->TopRightCorner (insetArea, light, dark, hilite);
-
- // • BotLeft 3
- // • Colors same as previous corner
- this->BotLeftCorner (insetArea, light, dark, hilite);
-
- // • BotRight 4
- SetRGBColor (light, kRGB4BitGray1, kRGB4BitGray1, kRGB4BitGray1);
- SetRGBColor (dark, kRGB4BitGray1, kRGB4BitGray1, kRGB4BitGray1);
- this->BotRightCorner (insetArea, light, dark, hilite);
-
- }
- else // • Draw the unhilited button
- {
- // • Outside edge of bottom right shadow
- SetRGBColor (color, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3);
- SetIfColor (color);
- MoveTo (controlArea.left + 2, controlArea.bottom - 1);
- LineTo (controlArea.right - 3, controlArea.bottom - 1);
- MoveTo (controlArea.right - 1, controlArea.bottom - 3);
- LineTo (controlArea.right - 1, controlArea.top + 2);
-
- // • Inset our rectangle as we move to the next level
- InsetRect (controlArea, 1, 1);
-
- // • Light on edge of button - light source edge
- SetIfColor (gRGBWhite);
- MoveTo (controlArea.left, controlArea.bottom - 2);
- LineTo (controlArea.left, controlArea.top + 1);
- MoveTo (controlArea.left + 1, controlArea.top);
- LineTo (controlArea.right - 2, controlArea.top);
-
- // • Inside edge of bottom right shadow
- SetRGBColor (color, kRGB4BitGray2, kRGB4BitGray2, kRGB4BitGray2);
- SetIfColor (color);
- MoveTo (controlArea.left + 1, controlArea.bottom - 1);
- LineTo (controlArea.right - 2, controlArea.bottom - 1);
- MoveTo (controlArea.right - 1, controlArea.bottom - 2);
- LineTo (controlArea.right - 1, controlArea.top + 1);
-
- // •• Now draw the corners
- // • TopLeft 1
- this->TopLeftCorner (insetArea, gRGBWhite, gRGBWhite, hilite);
-
- // • TopRight 2
- SetRGBColor (light, kRGB4BitGray2, kRGB4BitGray2, kRGB4BitGray2);
- this->TopRightCorner (insetArea, light, light, hilite);
-
- // • BotLeft 3
- // • Colors same as previous corner
- this->BotLeftCorner (insetArea, light, light, hilite);
-
- // • BotRight 4
- SetRGBColor (light, kRGB4BitGray2, kRGB4BitGray2, kRGB4BitGray2);
- SetRGBColor (dark, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3);
- this->BotRightCorner (insetArea, light, dark, hilite);
-
- }
-
-
- } // T3DTextButtonAdorner::Draw4Bit
-
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner::Draw1Bit
- // This routine is actually not called
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DTextButtonAdorner::Draw1Bit ( const CRect& /*rect */, Boolean /*hilite*/)
- {
- // We don't actually use this now
-
- } // T3DTextButtonAdorner::Draw1Bit
-
- //----------------------------------------------------------------------------------------
- // •• BUTTON FRAME
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner::Frame
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DTextButtonAdorner::Frame (const CRect& rect)
- {
- // • Draw the frame around the button this never changes
- FrameRoundRect (rect, kOvalWidth, kOvalHeight);
-
- } // T3DTextButtonAdorner::Frame
-
- //----------------------------------------------------------------------------------------
- // •• CORNER DRAWING
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner::TopLeftCorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DTextButtonAdorner::TopLeftCorner (const CRect& rect,
- const CRGBColor light,
- const CRGBColor dark,
- Boolean hilite )
- {
- if (hilite)
- {
- // • Set the outer corner pixel
- SetIfColor(dark);
- MoveTo(rect.left + 1, rect.top + 1);
- LineTo(rect.left + 1, rect.top + 1);
-
- // • Set the inner corner pixel
- SetIfColor(light);
- MoveTo(rect.left + 2, rect.top + 2);
- LineTo(rect.left + 2, rect.top + 2);
- }
- else
- {
- // • Set the outer corner pixel
- SetIfColor(light);
- MoveTo(rect.left + 1, rect.top + 1);
- LineTo(rect.left + 1, rect.top + 1);
-
- // • Set the inner corner pixel
- SetIfColor(dark);
- MoveTo(rect.left + 2, rect.top + 2);
- LineTo(rect.left + 2, rect.top + 2);
- }
-
- } // T3DTextButtonAdorner::TopLeftCorner
-
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner::TopRightCorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DTextButtonAdorner::TopRightCorner ( const CRect& rect,
- const CRGBColor light,
- const CRGBColor dark,
- Boolean hilite )
- {
- if (hilite)
- {
- // • Set the outer corner pixel
- SetIfColor(dark);
- MoveTo(rect.right - 2, rect.top + 1);
- LineTo(rect.right - 2, rect.top + 1);
-
- // • Set the inner corner pixel
- SetIfColor(light);
- MoveTo(rect.right - 3, rect.top + 2);
- LineTo(rect.right - 3, rect.top + 2);
- }
- else
- {
- // • Set the outer corner pixel
- SetIfColor(light);
- MoveTo(rect.right - 2, rect.top + 1);
- LineTo(rect.right - 2, rect.top + 1);
-
- // • Set the inner corner pixel
- SetIfColor(dark);
- MoveTo(rect.right - 3, rect.top + 2);
- LineTo(rect.right - 3, rect.top + 2);
- }
-
- } // T3DTextButtonAdorner::TopRightCorner
-
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner::BotLeftCorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DTextButtonAdorner::BotLeftCorner ( const CRect& rect,
- const CRGBColor light,
- const CRGBColor dark,
- Boolean hilite )
- {
- if (hilite)
- {
- // • Set the outer corner pixel
- SetIfColor(dark);
- MoveTo(rect.left + 1, rect.bottom - 2);
- LineTo(rect.left + 1, rect.bottom - 2);
-
- // • Set the inner corner pixel
- SetIfColor(light);
- MoveTo(rect.left + 2, rect.bottom - 3);
- LineTo(rect.left + 2, rect.bottom - 3);
- }
- else
- {
- // • Set the outer corner pixel
- SetIfColor(light);
- MoveTo(rect.left + 1, rect.bottom - 2);
- LineTo(rect.left + 1, rect.bottom - 2);
-
- // • Set the inner corner pixel
- SetIfColor(dark);
- MoveTo(rect.left + 2, rect.bottom - 3);
- LineTo(rect.left + 2, rect.bottom - 3);
- }
- } // T3DTextButtonAdorner::BotLeftCorner
-
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner::BotRightCorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DTextButtonAdorner::BotRightCorner (const CRect& rect,
- const CRGBColor light,
- const CRGBColor dark,
- Boolean hilite)
- {
- if (hilite)
- {
- // • Set the outer corner pixel
- SetIfColor(light);
- MoveTo(rect.right - 2, rect.bottom - 2);
- LineTo(rect.right - 2, rect.bottom - 2);
-
- // • Set the inner corner pixel
- SetIfColor(dark);
- MoveTo(rect.right - 3, rect.bottom - 3);
- LineTo(rect.right - 3, rect.bottom - 3);
- }
- else
- {
- // • Set the outer corner pixel
- SetIfColor(dark);
- MoveTo(rect.right - 2, rect.bottom - 2);
- LineTo(rect.right - 2, rect.bottom - 2);
-
- // • Set the inner corner pixel
- SetIfColor(light);
- MoveTo(rect.right - 3, rect.bottom - 3);
- LineTo(rect.right - 3, rect.bottom - 3);
- }
-
- } // T3DTextButtonAdorner::BotRightCorner
-
- //----------------------------------------------------------------------------------------
- // ••• 3DIconButton class and auxiliary adorner •••
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner
- // This is an auxiliary adorner for T3DIconButtons
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::I3DIconAdorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- #undef Inherited
- #define Inherited TAdorner
- DefineClass(T3DIconAdorner, TAdorner);
-
- void T3DIconAdorner::I3DIconAdorner ( Boolean freeOnDeletion )
- {
- // • Call our superclass to complete initialization
- this->IAdorner ( k3DIconAdorner,freeOnDeletion );
-
- } // T3DIconAdorner::I3DIconAdorner
-
- //----------------------------------------------------------------------------------------
- // •• DRAWING
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::Draw
- //----------------------------------------------------------------------------------------
- //
- // This overridden draw method handles the drawing of the buttons border and then
- // branches to the appropriate appropriate method to draw the buttons contents, based
- // on the bit depth of the device being drawn to. Currently this method supports 1, 4,
- // and 8 bit or more devices.
-
- #pragma segment A3DControlRes
-
- void T3DIconAdorner::Draw ( TView* itsView, const VRect& /*area*/ )
- {
- VRect theRect;
- CRect qdArea;
- short pixelSize;
-
- // • Instantiate a stack based object that saves our graphic state
- CGraphicsState aGraphicsState;
-
- // • Coerce the view to a control and then get its QD area
- TControl* theControl = (TControl*)itsView;
- theControl->ControlArea ( theRect );
- theControl->ViewToQDRect ( theRect, qdArea );
-
- // • Frame button with a black border that has a pixel missing in each corner
- // this is drawn outside the while loop because it is always in black & white
- if (((TControl *)itsView)->IsDimmed())
- SetIfColor(kMediumGray);
- else
- SetIfColor ( gRGBBlack );
- this->Frame ( qdArea );
-
- // • Inset the area in preparartion for the drawing of the buttons content
- InsetRect ( qdArea, 1, 1 );
-
- // • Instantiate the stack based object that handles the per device clipping
- // the area is passed in so that the object can do clipping from it
- if (((TControl *)itsView)->IsDimmed())
- {
- // Hack for non-CQD
- CDrawPerDevice device ( qdArea );
- while ( device.NextDevice ( pixelSize ) )
- {
- if ( pixelSize < 4 )
- {
- // Redraw the frame because it didn't draw if we're in non-CQD
- CRect tempArea = qdArea;
- CPenNormal();
- InsetRect(tempArea, -1, -1);
- this->Frame ( tempArea );
- }
- }
- }
- else
- {
- CDrawPerDevice device ( qdArea );
-
- // • We will cycle through all of the devices, drawing will be handle based on
- // the pixel size for each device
- while ( device.NextDevice ( pixelSize ) )
- {
-
- // • Draw the button with full colors - there should really be two levels of
- // drawing here, one for 4 bit color and one for 8 bit.
- if ( pixelSize >= 8 )
- {
-
- // • Draw the button assuming 8 bit or better color
- this->Draw8Bit ( qdArea, theControl->fHilite );
-
- }
- else if ( pixelSize == 4 ) // • Draw with only 16 colors
- {
-
- // • For now we will draw the 1 bit style for 4 bit, but this should be
- // replaced with a 4 bit algorithm which will give you 3 shades of gray
- this->Draw4Bit ( qdArea, theControl->fHilite );
-
- }
- else if ( pixelSize < 4 ) // • Draw with 4 colors or less (no grays)
- {
- // • Draw the 1 bit style for anything under 4 bit
- this->Draw1Bit ( qdArea, theControl->fHilite );
-
- }
- }
- }
-
- } // T3DIconAdorner::Draw
-
- //----------------------------------------------------------------------------------------
- // •• PRIVATE DRAWING
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::Draw8Bit
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconAdorner::Draw8Bit ( const CRect& rect, Boolean hilite )
- {
- CRect insetArea;
- CRect controlArea;
- CRGBColor color;
- CRGBColor light;
- CRGBColor dark;
-
- // • Make a copy of the rect passed in
- controlArea = rect;
-
- // • Save off the area passed in
- insetArea = rect;
-
- // • Draw the hilited button
- if ( hilite )
- {
- // • Outside edge of left top shadow
- SetRGBColor ( color, kRGB8BitGray9, kRGB8BitGray9, kRGB8BitGray9 );
- SetIfColor ( color );
- this->TopLeftSide ( controlArea );
-
- // • Outside edge of bottom right shadow
- SetRGBColor ( color, kRGB8BitGray3, kRGB8BitGray3, kRGB8BitGray3 );
- SetIfColor ( color );
- this->BotRightSide ( controlArea );
-
- // • Inset our rectangle as we move to the next level
- InsetRect ( controlArea, 1, 1 );
-
- // • Inside edge of left top shadow
- SetRGBColor ( color, kRGB8BitGray8, kRGB8BitGray8, kRGB8BitGray8 );
- SetIfColor ( color );
- this->TopLeftSide ( controlArea );
-
- // • Inside edge of bottom right shadow
- color = kMediumLightGray;
- SetIfColor ( color );
- this->BotRightSide ( controlArea );
-
- // •• Now draw the corners
- // • TopLeft 1
- SetRGBColor ( light, kRGB8BitGray9, kRGB8BitGray9, kRGB8BitGray9 );
- SetRGBColor ( dark, kRGB8BitGray10, kRGB8BitGray10, kRGB8BitGray10 );
- this->TopLeftCorner ( insetArea, light, dark );
-
- // • TopRight 2
- light = kMediumGray;
- SetRGBColor ( dark, kRGB8BitGray7, kRGB8BitGray7, kRGB8BitGray7 );
- this->TopRightCorner ( insetArea, light, dark );
-
- // • BotLeft 3
- // • Colors same as previous corner
- this->BotLeftCorner ( insetArea, light, dark );
-
- // • BotRight 4
- light = kLightGray2;
- SetRGBColor ( dark, kRGB8BitGray3, kRGB8BitGray3, kRGB8BitGray3 );
- this->BotRightCorner ( insetArea, light, dark, hilite );
-
- // • Setup fill color for buttons face - hilite
- color = kMediumGray;
-
- }
- else // • Draw the unhilited button
- {
- // • Outside edge of left top shadow
- color = kLightGray2;
- SetIfColor ( color );
- this->TopLeftSide ( controlArea );
-
- // • Outside edge of bottom right shadow
- SetRGBColor ( color, kRGB8BitGray7, kRGB8BitGray7, kRGB8BitGray7 );
- SetIfColor ( color );
- this->BotRightSide ( controlArea );
-
- // • Inset our rectangle as we move to the next level
- InsetRect ( controlArea, 1, 1 );
-
- // • Light on edge of button - light source edge
- SetIfColor ( gRGBWhite );
- this->TopLeftSide ( controlArea );
-
- // • Inside edge of bottom right shadow
- color = kMediumGray;
- SetIfColor ( color );
- this->BotRightSide ( controlArea );
-
- // •• Now draw the corners
- // • TopLeft 1
- this->TopLeftCorner ( insetArea, gRGBWhite, gRGBWhite );
-
- // • TopRight 2
- SetRGBColor ( light, kRGB8BitGray3, kRGB8BitGray3, kRGB8BitGray3 );
- this->TopRightCorner ( insetArea, light, light );
-
- // • BotLeft 3
- // • Colors same as previous corner
- this->BotLeftCorner ( insetArea, light, light );
-
- // • BotRight 4
- SetRGBColor ( light, kRGB8BitGray8, kRGB8BitGray8, kRGB8BitGray8 );
- SetRGBColor ( dark, kRGB8BitGray9, kRGB8BitGray9, kRGB8BitGray9 );
- this->BotRightCorner ( insetArea, light, dark, hilite );
-
- // • Setup fill color for button face
- color = kLightGray2;
-
- }
-
- // • Inset our rectangle so that we can fill the rest of the area
- InsetRect ( controlArea, 1, 1 );
-
- // • Now we will fill the rest of the button NOTE: color was setup at the
- // end of either the hilite or normal draw routines
- SetIfColor ( color );
- PaintRect ( controlArea );
-
- } // T3DIconAdorner::Draw8Bit
-
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::Draw4Bit
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconAdorner::Draw4Bit ( const CRect& rect, Boolean hilite )
- {
- CRect insetArea;
- CRect controlArea;
- CRGBColor color;
- CRGBColor light;
- CRGBColor dark;
-
- // • Make a copy of the rect passed in
- controlArea = rect;
-
- // • Save off the area passed in
- insetArea = rect;
-
- // • Draw the hilited button
- if ( hilite )
- {
- // • Outside edge of left top shadow
- SetRGBColor ( color, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3 );
- SetIfColor ( color );
- this->TopLeftSide ( controlArea );
-
- // • Outside edge of bottom right shadow
- SetRGBColor ( color, kRGB4BitGray1, kRGB4BitGray1, kRGB4BitGray1 );
- SetIfColor ( color );
- this->BotRightSide ( controlArea );
-
- // • Inset our rectangle as we move to the next level
- InsetRect ( controlArea, 1, 1 );
-
- // • Inside edge of left top shadow
- SetRGBColor ( color, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3 );
- SetIfColor ( color );
- this->TopLeftSide ( controlArea );
-
- // • Inside edge of bottom right shadow
- SetRGBColor ( color, kRGB4BitGray1, kRGB4BitGray1, kRGB4BitGray1 );
- SetIfColor ( color );
- this->BotRightSide ( controlArea );
-
- // •• Now draw the corners
- // • TopLeft 1
- SetRGBColor ( light, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3 );
- this->TopLeftCorner ( insetArea, light, light );
-
- // • TopRight 2
- SetRGBColor ( light, kRGB4BitGray2, kRGB4BitGray2, kRGB4BitGray2 );
- this->TopRightCorner ( insetArea, light, light );
-
- // • BotLeft 3
- SetRGBColor ( light, kRGB4BitGray2, kRGB4BitGray2, kRGB4BitGray2 );
- this->BotLeftCorner ( insetArea, light, light );
-
- // • BotRight 4
- SetRGBColor ( light, kRGB4BitGray1, kRGB4BitGray1, kRGB4BitGray1 );
- this->BotRightCorner ( insetArea, light, light, hilite );
-
- // • Setup fill color for button face - hilite
- SetRGBColor ( color, kRGB4BitGray2, kRGB4BitGray2, kRGB4BitGray2 );
-
- }
- else // • Draw the unhilited button
- {
- // • Outside edge of left top shadow
- SetRGBColor ( color, kRGB4BitGray1, kRGB4BitGray1, kRGB4BitGray1 );
- SetIfColor ( color );
- this->TopLeftSide ( controlArea );
-
- // • Outside edge of bottom right shadow
- SetRGBColor ( color, kRGB4BitGray2, kRGB4BitGray2, kRGB4BitGray2 );
- SetIfColor ( color );
- this->BotRightSide ( controlArea );
-
- // • Inset our rectangle as we move to the next level
- InsetRect ( controlArea, 1, 1 );
-
- // • Light on edge of button - light source edge
- SetIfColor ( gRGBWhite );
- this->TopLeftSide ( controlArea );
-
- // • Inside edge of bottom right shadow
- SetRGBColor ( color, kRGB4BitGray2, kRGB4BitGray2, kRGB4BitGray2 );
- SetIfColor ( color );
- this->BotRightSide ( controlArea );
-
- // •• Now draw the corners
- // • TopLeft 1
- this->TopLeftCorner ( insetArea, gRGBWhite, gRGBWhite );
-
- // • TopRight 2
- SetRGBColor ( light, kRGB4BitGray1, kRGB4BitGray1, kRGB4BitGray1 );
- this->TopRightCorner ( insetArea, light, light );
-
- // • BotLeft 3
- // • Colors same as previous corner
- this->BotLeftCorner ( insetArea, light, light );
-
- // • BotRight 4
- SetRGBColor ( light, kRGB4BitGray3, kRGB4BitGray3, kRGB4BitGray3 );
- this->BotRightCorner ( insetArea, light, light, hilite );
-
- // • Setup fill color for button face
- SetRGBColor ( color, kRGB4BitGray1, kRGB4BitGray1, kRGB4BitGray1 );
-
- }
-
- // • Inset our rectangle so that we can fill the rest of the area
- InsetRect ( controlArea, 1, 1 );
-
- // • Now we will fill the rest of the button NOTE: color was setup at the
- // end of either the hilite or normal draw routines
- SetIfColor ( color );
- PaintRect ( controlArea );
-
- } // T3DIconAdorner::Draw4Bit
-
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::Draw1Bit
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconAdorner::Draw1Bit ( const CRect& rect, Boolean hilite )
- {
- CRect insetArea;
- CRect controlArea;
-
- CPenNormal();
-
- // • Make a copy of the rect passed in
- controlArea = rect;
-
- // • Save off the area passed in
- insetArea = controlArea;
-
- // • First we paint the inside white
- PenPat(&qd.white);
- ForeColor ( whiteColor );
- PaintRect ( controlArea );
-
- // • Outside edge of bottom right shadow
- PenPat ( &qd.gray );
- ForeColor ( blackColor );
- this->BotRightSide ( controlArea );
-
- // • Inset the rectangle again for the next level
- InsetRect ( controlArea, 1, 1 );
-
- // • Inside edge of bottom right shadow
- this->BotRightSide ( controlArea );
-
- // • We are hiliting so we need to invert the whole thing
- if ( hilite )
- InvertRect ( insetArea );
-
- } // T3DIconAdorner::Draw1Bit
-
- //----------------------------------------------------------------------------------------
- // •• BUTTON FRAME
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::Frame
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconAdorner::Frame ( const CRect& rect )
- {
- // • Draw the frame around the button this never changes
- MoveTo ( rect.left, rect.bottom - 2 );
- LineTo ( rect.left, rect.top + 1 );
- MoveTo ( rect.left + 1, rect.top );
- LineTo ( rect.right - 2, rect.top );
- MoveTo ( rect.left + 1, rect.bottom - 1 );
- LineTo ( rect.right - 2, rect.bottom - 1 );
- MoveTo ( rect.right - 1, rect.bottom - 2 );
- LineTo ( rect.right - 1, rect.top + 1 );
-
- } // T3DIconAdorner::Frame
-
- //----------------------------------------------------------------------------------------
- // •• EDGE DRAWING
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::TopLeftSide
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconAdorner::TopLeftSide ( const CRect& rect )
- {
- MoveTo ( rect.left,rect.bottom-2 );
- LineTo ( rect.left,rect.top );
- LineTo ( rect.right-2,rect.top );
-
- } // T3DIconAdorner::TopLeftSide
-
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::BotRightSide
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconAdorner::BotRightSide ( const CRect& rect )
- {
- MoveTo ( rect.left,rect.bottom-1 );
- LineTo ( rect.right-1,rect.bottom-1 );
- LineTo ( rect.right-1,rect.top );
-
- } // T3DIconAdorner::BotRightSide
-
- //----------------------------------------------------------------------------------------
- // •• CORNER DRAWING
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::TopLeftCorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconAdorner::TopLeftCorner ( const CRect& rect,
- const CRGBColor light,
- const CRGBColor dark )
- {
- // • Set the outer corner pixel
- SetIfColor(dark);
- MoveTo(rect.left, rect.top);
- LineTo(rect.left, rect.top);
-
- // • Set the inner corner pixel
- SetIfColor(light);
- MoveTo(rect.left + 1, rect.top + 1);
- LineTo(rect.left + 1, rect.top + 1);
-
- } // T3DIconAdorner::TopLeftCorner
-
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::TopRightCorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconAdorner::TopRightCorner ( const CRect& rect,
- const CRGBColor light,
- const CRGBColor dark )
- {
- // • Set the outer corner pixel
- SetIfColor(light);
- MoveTo(rect.right - 1, rect.top);
- LineTo(rect.right - 1, rect.top);
-
- // • Set the inner corner pixel
- SetIfColor(dark);
- MoveTo(rect.right - 2, rect.top + 1);
- LineTo(rect.right - 2, rect.top + 1);
-
- } // T3DIconAdorner::TopRightCorner
-
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::BotLeftCorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconAdorner::BotLeftCorner ( const CRect& rect,
- const CRGBColor light,
- const CRGBColor dark )
- {
- // • Set the outer corner pixel
- SetIfColor(light);
- MoveTo(rect.left, rect.bottom - 1);
- LineTo(rect.left, rect.bottom - 1);
-
- // • Set the inner corner pixel
- SetIfColor(dark);
- MoveTo(rect.left + 1, rect.bottom - 2);
- LineTo(rect.left + 1, rect.bottom - 2);
-
- } // T3DIconAdorner::BotLeftCorner
-
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner::BotRightCorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconAdorner::BotRightCorner ( const CRect& rect,
- const CRGBColor light,
- const CRGBColor dark,
- Boolean hilite )
- {
- if ( hilite )
- {
- // • Set the outer corner pixel
- SetIfColor(light);
- MoveTo(rect.right - 1, rect.bottom - 1);
- LineTo(rect.right - 1, rect.bottom - 1);
-
- // • Set the inner corner pixel
- SetIfColor(dark);
- MoveTo(rect.right - 2, rect.bottom - 2);
- LineTo(rect.right - 2, rect.bottom - 2);
- }
- else
- {
- // • Set the outer corner pixel
- SetIfColor(dark);
- MoveTo(rect.right - 1, rect.bottom - 1);
- LineTo(rect.right - 1, rect.bottom - 1);
-
- // • Set the inner corner pixel
- SetIfColor(light);
- MoveTo(rect.right - 2, rect.bottom - 2);
- LineTo(rect.right - 2, rect.bottom - 2);
- }
-
- } // T3DIconAdorner::BotRightCorner
-
- //----------------------------------------------------------------------------------------
- // CLASS: TIconSuite
- // The T3DIconButton class is based from this one. However, you can use this
- // class alone if you wish. It will draw an icon suite and allow you to
- // apply standard masks to respond to events
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // •• INITIALIZATION & DISPOSAL
- //----------------------------------------------------------------------------------------
- // TIconSuite::Initialize
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- #undef Inherited
- #define Inherited TControl
- DefineClass(TIconSuite, TControl);
-
- void TIconSuite::Initialize () // OVERRIDE
- {
- fIconSuiteRsrcID = kNoResource;
- fAlignment = atNone;
- fDataHandle = NULL;
- fSelectorValue = svAllAvailableData;
-
- } // TIconSuite::Initialize
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::IIconSuite
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void TIconSuite::IIconSuite ( TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- ResNumber itsRsrcID,
- IconAlignmentType alignment,
- IconSelectorValue selectorValue)
- {
- FailInfo fi;
-
- this->IControl ( itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet );
-
- // • Setup our fields
- fAlignment = alignment;
- fEventNumber = mIconSuiteHit; // We will use the mIconSuiteHit constant
-
- // • Installs the icon suite
- this->SetIconSuiteRsrcID ( itsRsrcID,selectorValue,kDontRedraw );
-
- // • Default is to enable hit testing
- this->SetEnable ( true );
-
- } // TIconSuite::IIconSuite
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::DoPostCreate
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void TIconSuite::DoPostCreate(TDocument *itsDocument)
- {
- Inherited::DoPostCreate(itsDocument);
-
- fEventNumber = mIconSuiteHit; // We will use the mIconSuiteHit constant
- fAlignment = atNone;
-
- // • Installs the icon suite - use the fUserArea field of the View resource
- // as the icon suite
- this->SetIconSuiteRsrcID((short) fUserArea,svAllAvailableData,kDontRedraw);
-
- // • Default is to enable hit testing
- this->SetEnable ( true );
- }
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::Clone
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- TObject* TIconSuite::Clone () // OVERRIDE
- {
- TIconSuite* aClonedIconSuite;
- Handle itsRsrcHandle;
-
- // • First call Inherited clone and coerce the result to our type
- aClonedIconSuite = ( TIconSuite* )( Inherited::Clone ());
-
- // • Setup the cloned icon suite's fields
- aClonedIconSuite->fDataHandle = NULL;
- aClonedIconSuite->fAlignment = fAlignment;
-
- // • Now get a new copy of the resource handle and place it in the data field
- if ( fDataHandle )
- {
- // • Make the resource non-purgeable, so the Toolbox doesn't die
- GetIconSuite ( &itsRsrcHandle, fIconSuiteRsrcID, fSelectorValue );
-
- aClonedIconSuite->fDataHandle = itsRsrcHandle;
-
- // • Check to see if it is a NIL resource
- FailNILResource ( aClonedIconSuite->fDataHandle );
- }
-
- // • Return the cloned icon suite
- return aClonedIconSuite;
-
- } // TIconSuite::Clone
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::Free
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlClose
-
- void TIconSuite::Free () // OVERRIDE
- {
- // • Get rid of the icon suite
- this->ReleaseIconSuite ();
-
- Inherited::Free ();
-
- } // TIconSuite::Free
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::ReleaseIconSuite
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void TIconSuite::ReleaseIconSuite ()
- {
- // • Set the rsrc ID field to nothing
- fIconSuiteRsrcID = kNoResource;
-
- // • If there is a data handle then dispose of the icon suite
- if ( fDataHandle )
- {
- OSErr anError;
-
- anError = DisposeIconSuite ( fDataHandle, true );
- fDataHandle = NULL;
- }
-
- } // TIconSuite::ReleaseIconSuite
-
- //----------------------------------------------------------------------------------------
- // •• ACCESSORS
- //----------------------------------------------------------------------------------------
- // TIconSuite::GetIconRect
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void TIconSuite::GetIconRect ( VRect& theRect )
- {
- this->ControlArea ( theRect );
-
- } // <- GetIconRect
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::SetIconSuite
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void TIconSuite::SetIconSuite ( Handle theSuite, Boolean redraw )
- {
- ResNumber theID;
- ResType theType;
- CStr255 name;
-
- // • Release the existing icon suite and set the data field to
- // the new icon suite
- this->ReleaseIconSuite();
- fDataHandle = theSuite;
-
- // • Get the rsrc ID from the icon suite's handle
- GetResInfo ( theSuite, &theID, &theType, name) ;
- if ( ResError() == noErr )
- fIconSuiteRsrcID = theID;
-
- // • Get everything redrawn so that the new icon can be displayed, if needed
- if ( redraw )
- this->ForceRedraw ();
-
- } // TIconSuite::SetIconSuite
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::SetIconSuiteRsrcID
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void TIconSuite::SetIconSuiteRsrcID ( short itsRsrcID, IconSelectorValue selectorValue, Boolean redraw )
- {
- FailInfo fi;
- Handle itsRsrcHandle;
-
- if ( itsRsrcID != kNoResource )
- {
- Try(fi)
- {
- // • Make the resource non-purgeable, so the Toolbox doesn't die
- GetIconSuite ( &itsRsrcHandle, itsRsrcID, fSelectorValue );
-
- // • Check to see if it is a NIL resource
- FailNILResource ( itsRsrcHandle );
-
- // • Release the existing icon suite
- this->ReleaseIconSuite();
-
- // • Place the resource handle in our data field
- fDataHandle = itsRsrcHandle;
- fIconSuiteRsrcID = itsRsrcID;
- fSelectorValue = selectorValue;
-
- // • Hey! everything worked fine, we're out of here!!
- fi.Success ();
- }
- else // Recover
- {
- fi.ReSignal ();
- }
-
- // • Get everything redrawn so that the new icon can be displayed, if needed
- if ( redraw )
- this->ForceRedraw ();
-
- }
-
- } // TIconSuite::SetIconSuiteRsrcID
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::SetAlignment
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void TIconSuite::SetAlignment ( IconAlignmentType newAlignment, Boolean redraw )
- {
- // • Setup the field to the new alignment value
- fAlignment = newAlignment;
-
- // • Get everything redrawn so that the new icon can be displayed, if needed
- if ( redraw )
- this->ForceRedraw ();
-
- } // TIconSuite::SetAlignment
-
- //----------------------------------------------------------------------------------------
- // •• DRAWING
- //----------------------------------------------------------------------------------------
- // TIconSuite::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void TIconSuite::Draw ( const VRect& area ) // OVERRIDE
- {
- // • Get the icon plotted with the "ttNone" transorm applied
- // this transform shows the icon in its normal state
- this->DoPlotIconSuite ( ttNone );
-
- Inherited::Draw ( area );
-
- } // <- Draw
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::DoPlotIconSuite PRIVATE
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void TIconSuite::DoPlotIconSuite ( IconTransformType transform ) // OVERRIDE
- {
- SignedByte oldState;
- VRect theRect;
- CRect theQDRect;
-
- // • We will only do something if we have a datahandle
- if ( fDataHandle )
- {
- // • If the data handle we have is a resource then make sure its loaded
- if ( IsAResource ( fDataHandle ))
- LoadResource ( fDataHandle );
-
- if ( *fDataHandle ) // If there's room for the icon…
- {
- PenNormal(); // NECESSARY?
-
- // • Get a Quickdraw rectangle of the control's extent
- this->GetIconRect ( theRect );
- this->ViewToQDRect ( theRect, theQDRect );
-
- // • Save off the state of the data handle
- oldState = HGetState ( fDataHandle );
- HNoPurge ( fDataHandle );
- HLock ( fDataHandle );
-
- // • Get the icon plotted using the transform passed in as
- // well as the current alignment
- PlotIconSuite ( theQDRect, fAlignment, transform, fDataHandle);
-
- // • Restore the dtata handle's state
- HSetState ( fDataHandle, oldState );
- }
- }
-
- } // TIconSuite::DoPlotIconSuite
-
- //----------------------------------------------------------------------------------------
- // •• STATE
- //----------------------------------------------------------------------------------------
- // TIconSuite::Dim
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void TIconSuite::Dim () // OVERRIDE
- {
- // • Plot the icon disabled if we are dimmed
- this->DoPlotIconSuite ( ttDisabled );
-
- } // TIconSuite::Dim
-
- //----------------------------------------------------------------------------------------
- // TIconSuite::Hilite
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void TIconSuite::Hilite () // OVERRIDE
- {
-
- // • If the icon is hilited then plot it "selected" otherwise plot is as
- // normal in its unselected state
- if ( fHilite )
- this->DoPlotIconSuite ( ttSelected );
- else
- this->DoPlotIconSuite ( ttNone );
-
- } // TIconSuite::Hilite
-
- //----------------------------------------------------------------------------------------
- // CLASS: T3DIconButton
- //----------------------------------------------------------------------------------------
-
- const short kDefaultSize = 32;
- //----------------------------------------------------------------------------------------
- // T3DIconButton::Initialize
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- #undef Inherited
- #define Inherited TIconSuite
- DefineClass(T3DIconButton, TIconSuite);
-
- void T3DIconButton::Initialize () // Override
- {
- f3DIconAdorner = NULL;
- fIconSize = kDefaultSize; // Use 32x32 icons by default
- fMode = kButtonMode; // Use button mode by default
- fState = false;
-
- } // T3DIconButton::Initialize
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::I3DButton
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void T3DIconButton::I3DIconButton ( TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- short iconSize,
- ResNumber itsRsrcID,
- ButtonMode mode,
- Boolean state )
- {
- IconSelectorValue selectorValue;
-
- switch ( iconSize )
- {
- case 12:
- selectorValue = svAllMiniData;
- break;
- case 16:
- selectorValue = svAllSmallData;
- break;
- case 32:
- selectorValue = svAllLargeData;
- break;
- }
-
- // • Get our superclass setup
- this->IIconSuite ( itsSuperView, itsLocation, itsSize,
- itsHSizeDet, itsVSizeDet,
- itsRsrcID, atAbsoluteCenter, selectorValue );
-
- fIconSize = iconSize;
- this->SetMode ( mode );
- fState = state;
- fEventNumber = mIconButtonHit;
-
- // • Get the correct hiliteState setup
- if ( fState )
- this->HiliteState ( fState, kRedraw );
-
- // • If we are being built procedurally then build the adorner
- if ( f3DIconAdorner == NULL )
- this->CreateButtonAdorner ();
-
- } // T3DIconButton::I3DButton
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::DoPostCreate
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void T3DIconButton::DoPostCreate ( TDocument *itsDocument ) // Override
- {
-
- Inherited::DoPostCreate ( itsDocument );
-
- fEventNumber = mIconButtonHit;
-
- if ( f3DIconAdorner == NULL )
- this->CreateButtonAdorner ();
-
- } // T3DIconButton::DoPostCreate
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::CreateButtonAdorner
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void T3DIconButton::CreateButtonAdorner ()
- {
-
- // • Add the 3D Button Adorner
- T3DIconAdorner* adorner = new T3DIconAdorner;
- adorner->I3DIconAdorner ( kFreeOnDeletion );
- f3DIconAdorner = adorner;
- this->AddAdorner ( adorner, kAdornFirst, kDontInvalidate );
-
- } // T3DIconButton::CreateButtonAdorner
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::GetIconRect
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconButton::GetIconRect ( VRect& theRect )
- {
- this->ControlArea ( theRect );
-
- VCoordinate iconSize = this->GetIconSize ( theRect.GetSize () );
-
- // Center the icon
- theRect.top += ( theRect.bottom - theRect.top - iconSize ) / 2;
- theRect.bottom = theRect.top + iconSize;
- theRect.left += ( theRect.right - theRect.left - iconSize ) / 2;
- theRect.right = theRect.left + iconSize;
-
- } // T3DIconButton::GetIconRect
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::GetIconSize
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- short T3DIconButton::GetIconSize ( const VPoint& /*viewSize*/ )
- {
- return fIconSize;
-
- } // T3DIconButton::GetIconSize
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::Hilite
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconButton::Hilite () // Override
- {
- VRect area;
- this->GetExtent ( area) ;
- f3DIconAdorner->Draw ( this, area );
-
- Inherited::Hilite ();
-
- } // T3DIconButton::Hilite
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::Dim
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlRes
-
- void T3DIconButton::Dim () // Override
- {
- Inherited::Dim ();
-
- } // T3DIconButton::Dim
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::SetIconSuite
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void T3DIconButton::SetIconSuite ( Handle theSuite, Boolean redraw )
- {
-
- Inherited::SetIconSuite ( theSuite, redraw );
-
- this->SetAlignment ( atAbsoluteCenter, redraw );
-
- } // T3DIconButton::SetIconSuite
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::SetIconSuiteRsrcID
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void T3DIconButton::SetIconSuiteRsrcID ( short itsRsrcID,
- IconSelectorValue selectorValue,
- Boolean redraw )
- {
- Inherited::SetIconSuiteRsrcID ( itsRsrcID, selectorValue, redraw );
- this->SetAlignment ( atAbsoluteCenter,redraw );
-
- } // T3DIconButton::SetIconSuiteRsrcID
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::SetIconRsrcID
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- void T3DIconButton::SetIconRsrcID ( short itsRsrcID, Boolean redraw )
- {
- VRect theRect;
- IconSelectorValue selectorValue;
-
- this->ControlArea ( theRect );
- switch ( this->GetIconSize ( theRect.GetSize () ) )
- {
- case 12:
- selectorValue = svAllMiniData;
- break;
- case 16:
- selectorValue = svAllSmallData;
- break;
- case 32:
- selectorValue = svAllLargeData;
- break;
- }
-
- this->SetIconSuiteRsrcID ( itsRsrcID, selectorValue, redraw );
-
- } // T3DIconButton::SetIconRsrcID
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::SetMode
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- void T3DIconButton::SetMode ( ButtonMode newMode )
- {
- fMode = newMode;
-
- } // T3DIconButton::SetMode
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::GetMode
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlOpen
-
- ButtonMode T3DIconButton::GetMode ()
- {
- return fMode;
-
- } // T3DIconButton::GetMode
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::IsSelected
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlNonRes
-
- Boolean T3DIconButton::IsSelected ( void )
- {
- return fHilite;
-
- } // T3DIconButton::IsSelected
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton::TrackMouse
- //----------------------------------------------------------------------------------------
- #pragma segment A3DControlSelCommand
-
- void T3DIconButton::TrackMouse ( TrackPhase aTrackPhase,
- VPoint& ,
- // anchorPoint
- VPoint& ,
- // previousPoint
- VPoint& nextPoint,
- Boolean ) // OVERRIDE
- {
- if (!this->IsDimmed())
- switch (aTrackPhase)
- {
- case trackBegin:
- fState = fHilite;
- this->HiliteState ( true, kRedraw );
- break;
- case trackContinue:
- if (this->ContainsMouse ( nextPoint ))
- this->HiliteState ( true, kRedraw );
- else
- this->HiliteState ( fState, kRedraw);
- break;
- case trackEnd:
- if (this->ContainsMouse ( nextPoint ))
- {
- switch ( fMode )
- {
- case kButtonMode:
- if ( fHilite )
- this->HiliteState ( false, kRedraw);
- break;
- case kSwitchMode:
- this->HiliteState ( !fHilite, kRedraw);
- break;
- case kRadioMode:
- if ( !fHilite )
- this->HiliteState ( true, kRedraw );
- break;
- }
-
- this->HandleEvent ( fEventNumber, this, NULL );
- }
- break;
- }
- } // T3DIconButton::TrackMouse
-